Filling Graphical Shapes Pixelbased methods 1 Boundary Fill

Filling Graphical Shapes Pixel-based methods 1

Boundary Fill l MS Paint CS-321 Dr. Mark L. Hornick 2

Boundary Fill l l Start at interior point “Paint” interior outward toward boundary l l How? Note: Boundary encounter determined by boundary pixel color CS-321 Dr. Mark L. Hornick 3

Boundary fill Interior point CS-321 Dr. Mark L. Hornick 4

Boundary Fill Algorithm l Don’t fill if current position is: l l l Boundary color Current fill color Otherwise l l Set fill color Recursively try neighbors l l l North, East, South, West Could also be NSEW, NEWS, etc. Each neighbor recursively performs algorithm until “stop” CS-321 Dr. Mark L. Hornick 5

Boundary Fill Patterns 4 -connected 8 -connected CS-321 Dr. Mark L. Hornick 6

4 -connected EWNS boundary fill CS-321 Dr. Mark L. Hornick 7

Boundary Fill Algorithm l Demo CS-321 Dr. Mark L. Hornick 8

Boundary Fill Problems l Recursive algorithm l l Recursion stops only on l l l Stack space issue Boundary color Current fill color What if some other fill color is already present? l i. e. pixels already in area to be filled CS-321 Dr. Mark L. Hornick 9

Flood Fill l l Similar to boundary fill But replaces “interior” color (i. e. not boundary) l l Floods through an area Fill area must be - initially – a consistent color Only one significant color is filled over Paint bucket tool l MS Paint actually uses flood fill CS-321 Dr. Mark L. Hornick 10

Fill Algorithm Summary l Vector edge model l Scan line fill l l Even-odd or non-zero winding Pixel model l 4 - or 8 - connected recursion l Boundary fill: overwrites all but boundary or current fill color Flood fill: overwrites only initially selected color l CS-321 Dr. Mark L. Hornick 11
- Slides: 11