More info

Sunday, 2 March 2014

Computer Graphics Notes - Lab 15 - INSIDE -OUTSIDE TESTS - BOUNDARY -FILL ALGORITHM - Cont.

Another approach to area filling is to start at a point inside a region and paint the interior outward toward the boundary. If the boundary is specified in a single color, the fill algorithm proceeds outward pixel-by-pixel until the boundary color is encountered. This method, called the boundary-fill algorithm, is particularly useful in interactive painting packages where interior points are easily selected. Using a graphics tablet or other interactive device, an artist or designer can sketch a figure outline, select a fill color or pattern from a color menu, and pick an interior point. The system then paints the figure interior. To display a solid color region (with no border), the designer can choose the fill color to be the same as the boundary color.

A boundary-fill procedure accepts as input the coordinates of an interior point(x, y), a fill color, and a boundary color. Starting from (x, y), the procedure tests neighboring positions to determine whether they are of the boundary color. If not, they are painted with the fill color, and their neighbors are tested. This process continues until all pixels up to the boundary color for the area have been tested.


Boundary defined regions may be either 4-connected or 8-connected. 
Four Connected Region
Start at a point inside the figure and paint with a particular color. Filling continues until a boundary color is encountered.

Four neighboring points are tested. These are the pixel positions that are right, left, above and below the current pixel. Areas filled by this method are called 4-connected. Here we will use one function 'getpixel'. 'getpixel' function gives the color of specified pixel and 'putpixel' function draws the pixel with specified color.

void boundaryFil!4 (int x, int y, int fill, int boundary)
{int current;
current = getpixel (x, y)
if (current! = boundary) && (current! = fill) then
{
putpixel(x, y, fill)
boundary Fill4 (x+1, y, fill, boundary);
boundaryFill4 (x-1, y, fill, boundary);
boundaryFil4 (x, y+1, fill, boundary);
boundaryFill4 (x, y-1, fill, boundary);
}
}
There is the following problem with 4-connected:



This problem has been solved using 8-connected method. Eight-connected fill algorithm where we test all eight adjacent pixels. For an 8-connected region every pixel in the region may be reached by a combination of moves in the two horizontal, two vertical and four diagonal directions. The 8-connected will fill the above area. So 4-connected produces the partial fill.

Same algorithm described above can be modified to 8-connected region algorithm by including four additional statements to test diagonal positions.

void boundary Fill8 (int x, int y, int fill, int boundary)
{int current;
current = getpixel (x, y)
if (current! = boundary) && (current! = fill) then
{
Putpixel (x, y, fill)
Boundary Fill 8 (x+1, y, fill, boundary);
Boundary Fill8 (x-1, y, fill, boundary);
Boundary Fill 8 (x, y+1, fill, boundary);
Boundary Fill 8 (x, y-1, fill, boundary);
Boundary Fill 8 (x+1, y+1, fill, boundary);
Boundary Fill 8 (x+1, y-1, fill, boundary);
Boundary Fill 8 (x-1, y+1, fill, boundary);
Boundary Fill 8 (x-1, y-1, fill, boundary);
}
}

No comments:

Post a Comment