Computer Graphics
Graphic Systems
Input-Output Devices
Scan Conversion a line
Scan Conversion Circle
Scan Converting Ellipse
Filled Area Primitives
2D Transformations
2D-Viewing
Clipping Techniques
Pointing & Positioning
3D Computer Graphics
Hidden Surfaces
Projection
Programs
Filled Area Primitives
Region filling is the process of filling image or region. Filling can be of boundary or interior region as shown in fig. Boundary Fill algorithms are used to fill the boundary and flood-fill algorithm are used to fill the interior.
Boundary Filled Algorithm:
This algorithm uses the recursive method. First of all, a starting pixel called as the seed is considered. The algorithm checks boundary pixel or adjacent pixels are colored or not. If the adjacent pixel is already filled or colored then leave it, otherwise fill it. The filling is done using four connected or eight connected approaches.
Four connected approaches is more suitable than the eight connected approaches.
Polymorphism in Java | Dynamic Method Dispatch
1. Four connected approaches: In this approach, left, right, above, below pixels are tested.
2. Eight connected approaches: In this approach, left, right, above, below and four diagonals are selected.
Boundary can be checked by seeing pixels from left and right first. Then pixels are checked by seeing pixels from top to bottom. The algorithm takes time and memory because some recursive calls are needed.
Problem with recursive boundary fill algorithm:
It may not fill regions sometimes correctly when some interior pixel is already filled with color. The algorithm will check this boundary pixel for filling and will found already filled so recursive process will terminate. This may vary because of another interior pixel unfilled.
So check all pixels color before applying the algorithm.
Algorithm:
- Procedure fill (x, y, color, color1: integer)
- int c;
- c=getpixel (x, y);
- if (c!=color) (c!=color1)
- {
- setpixel (x, y, color)
- fill (x+1, y, color, color 1);
- fill (x-1, y, color, color 1);
- fill (x, y+1, color, color 1);
- fill (x, y-1, color, color 1);
- }