FLOOD FILL algorithm in computer graphics.pptx

71 views 7 slides Dec 01, 2024
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Flood fill algorithm


Slide Content

FLOOD FILL ALGORITHM Presentation By Siddarth

CONTENT INTRODUCTION 4 –CONNECTED PIXELS 8-CONNECTED PIXELS EXAMPLE

INTRODUCTION The Flood Fill Algorithm is used for filling a connected area with a specific colour or pattern, starting from a particular point. It identifies all neighboring pixels of a given start pixel with the same color, replacing their colour with a new one. Flood fill algorithms are essential in various applications, including: Image editing software : Filling a closed region (like the paint bucket tool in MS Paint). Game development: For terrain filling or object colouring. Image processing: Detecting and highlighting regions of interest.

4-CONNECTED PIXEL Floodfill (x, y,fill_ color, old_color: integer) If (getpixel (x, y)=old_color) { setpixel (x, y, fill_color); Flood fill (x+1, y, fill_color, old_color); Flood fill (x-1, y, fill_color, old_color); Flood fill (x, y+1, fill_color, old_color); Flood fill (x, y-1, fill_color, old_color); } In a 4-connected pixel neighborhood, each pixel is considered connected to its horizontal and vertical neighbors, but not diagonally. This means that for a pixel, its neighbors are the pixels directly adjacent to it in the up, down, left, and right directions. ALGORITHM:

8-CONNECTED PIXELS In an 8-connected pixel neighborhood, each pixel is considered connected to all of its immediate neighbors, including the diagonals. This means that for a pixel, it is connected to its neighbors in all 8 directions (up, down, left, right, and diagonals). ALGORITHM: Floodfill (x, y,fill_ color, old_color: integer) If (getpixel (x, y)=old_color) { setpixel (x, y, fill_color); FloodFill (x + 1, y, targetColor , fillColor ) FloodFill (x - 1, y, targetColor , fillColor ) FloodFill (x, y + 1, targetColor , fillColor ) FloodFill (x, y - 1, targetColor , fillColor ) FloodFill (x + 1, y + 1, targetColor , fillColor ) FloodFill (x - 1, y + 1, targetColor , fillColor ) FloodFill (x + 1, y - 1, targetColor , fillColor ) FloodFill (x - 1, y - 1, targetColor , fillColor ) }

EXAMPLE Let’s assume we have an image represented as a 2D grid (matrix), where each cell contains a color value. The matrix could look like this: Before Flood Fill (image): 1 1 1 2 2 1 1 2 2 2 1 2 2 1 1 2 2 1 1 1 We want to fill the region connected to the pixel at position (0,0 ) with the new color 3. The pixel at (0,0) currently has color 1. After applying the 4-connected Flood Fill algorithm: After Flood Fill: 3 3 3 2 2 3 3 2 2 2 3 2 2 1 1 2 2 1 1 1 Explanation : We start from pixel (0,0) with color 1. The algorithm changes the color to 3 and recursively fills its 4-connected neighbors that also have color 1. The algorithm stops when there are no more connected pixels with the original color.

THANK YOU
Tags