13.08.2018 Views

[Studies in Computational Intelligence 481] Artur Babiarz, Robert Bieda, Karol Jędrasiak, Aleksander Nawrat (auth.), Aleksander Nawrat, Zygmunt Kuś (eds.) - Vision Based Systemsfor UAV Applications (2013, Sprin

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

148 A. <strong>Babiarz</strong>, R. <strong>Bieda</strong>, and K. Jaskot<br />

thus the equation 12 becomes<br />

which ends proof.<br />

<br />

11 1 1<br />

<br />

(15)<br />

2.6 Flood Fill Algorithm<br />

B<strong>in</strong>arized image com<strong>in</strong>g from the background subtraction algorithm conta<strong>in</strong>s<br />

measures like center of mass, bound<strong>in</strong>g box, geometrical moments etc. can be also<br />

calculated, and what’s very important, calculat<strong>in</strong>g these measures can be done at<br />

very small cost. The algorithm used for the label<strong>in</strong>g purpose (one among others) is<br />

called Flood Fill. This algorithm can be described best by the follow<strong>in</strong>g pseudo<br />

code.<br />

<strong>in</strong>t currLabel = 0;<br />

stack s;<br />

for (<strong>in</strong>t y = 1; y < HEIGHT-1; y+=SKIP)<br />

for (<strong>in</strong>t x = 1; x < WIDTH-1; x+=SKIP)<br />

if (img.pixel(x, y) == 255) {<br />

currLabel++;<br />

s.push(x, y);<br />

while (!s.empty()) {<br />

<strong>in</strong>t xx, yy;<br />

s.pop(xx, yy);<br />

if (img.pixel(xx, yy) == 255) {<br />

img.pixel(xx, yy) = currLabel;<br />

s.push(xx-1, yy-1);<br />

s.push(xx , yy-1);<br />

s.push(xx+1, yy-1);<br />

s.push(xx-1, yy );<br />

s.push(xx , yy );<br />

s.push(xx+1, yy );<br />

s.push(xx+1, yy+1);<br />

s.push(xx , yy+1);<br />

s.push(xx+1, yy+1);<br />

}<br />

}<br />

}<br />

In the above implementation parameters WIDTH and HEIGHT are dimensions of<br />

the image img be<strong>in</strong>g processed, parameter SKIP is for simple optimization based<br />

on the observation that know<strong>in</strong>g the m<strong>in</strong>imal size occupied on the raster by the<br />

objects to be labeled the algorithm does not need to start search<strong>in</strong>g for them from<br />

every pixel, it is enough to start search<strong>in</strong>g every n pixels, where n should be a bit

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!