Page 106 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 106
Lab on Computer Graphics
Notes the left. Then a flood fill was started inside the large shape, and the algorithm gave all pixels
inside the shape the new colour, leaving its borders and the pixels outside intact.
Figure 6.3: Example of Flood Fill
Algorithm
Seed(x, y) is the seed pixel
Push is a function for placing a pixel on the stack
Pop is a function for removing a pixel from the stack
Pixel(x, y) = seed(x, y)
Initialize stack
Push pixel(x, y)
While (stack not empty)
get a pixel from the stack
Pop Pixel (x, y)
If Pixel(x, y) < > New value then
Pixel(x, y) = New value
Else
If (Pixel(x + 1, y) < > New value and
Pixel(x+1, y) < > Boundary value then
Push Pixel(x+1, y)
If Pixel(x, y+1) < > New value and
Pixel(x, y+1) < > Boundary value then
Push Pixel(x, y+1)
If Pixel(x – 1, y) < > New value and
Pixel(x+1, y) < > Boundary value then
Push Pixel(x-1,y)
If Pixel(x, y-1) < > New value and
Pixel(x, y-1) < > Boundary value then
Push pixel(x, y-1)
End if
End while
100 LOVELY PROFESSIONAL UNIVERSITY