0% found this document useful (0 votes)
13 views40 pages

Area Filling Algorithms

The document discusses area filling algorithms used in computer graphics, including Seed Fill, Boundary Fill, and Flood Fill, along with their respective 4-connected and 8-connected variations. It outlines the principles of each algorithm, their applications, and provides code examples for implementation. Additionally, it covers concepts like the Inside-Outside Test and rules for polygon filling.

Uploaded by

ashish206003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views40 pages

Area Filling Algorithms

The document discusses area filling algorithms used in computer graphics, including Seed Fill, Boundary Fill, and Flood Fill, along with their respective 4-connected and 8-connected variations. It outlines the principles of each algorithm, their applications, and provides code examples for implementation. Additionally, it covers concepts like the Inside-Outside Test and rules for polygon filling.

Uploaded by

ashish206003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Area Filling Algorithms

Author: Pi Date: 2025.05.30


CONTENTS
1. Seed Fill | Boundary Fill | Flood Fill 2. What is Area Filling?

3. Seed Filling Algorithm (Overview) 4. Seed Fill – 4-Connected Algorithm

5. Seed Fill – 8-Connected Algorithm 6. Boundary Fill Algorithm (Overview)

7. Boundary Fill – 4-Connected 8. Boundary Fill – 8-Connected

9. Flood Fill Algorithm (Overview) 10. Flood Fill – 4-Connected

11. Flood Fill – 8-Connected 12. Inside-Outside Test (Polygon Filling)

13. Odd-Even Rule 14. Nonzero Winding Number Rule

15. Summary 16. Thank You

17. Boundary Fill – 4-Connected (Code) 18. Boundary Fill – 8-Connected (Code)

19. Flood Fill – 4-Connected (Code) 20. Flood Fill – 8-Connected (Code)
01
Seed Fill | Boundary Fill | Flood Fill
Seed Fill | Boundary Fill |
Flood Fill
Prepared by: Roll No. 5, 6, 7
BCA 5th Semester
Subject: Computer Graphics
02
What is Area Filling?
What is Area Filling?

Area Filling Filling Strategies Applications


Area filling is used to color or Two strategies: boundary-based Used in drawing tools, games,
paint regions in graphics. and interior-based filling. and image processing.
03
Seed Filling Algorithm (Overview)
Seed Filling Algorithm (Overview)
1 2 3

Start Point Color Replacement Types


Starts from a seed point inside Replaces specific color pixels Two types: 4-connected and 8-
the region. outward until condition fails. connected.
04
Seed Fill – 4-Connected Algorithm
Seed Fill – 4-Connected Algorithm
1 2 3

Neighbor Usage Color Replacement Boundary Condition


Uses 4 neighbors (left, right, Recursively replaces default Stops at boundary or mismatch.
top, bottom). color with fill color.
05
Seed Fill – 8-Connected Algorithm
Seed Fill – 8-Connected
Algorithm
1 Diagonal Neighbors
Includes diagonal neighbors.

2 Complex Regions
Handles curved/complex regions better.

3 Connectivity
More complete than 4-connected.
06
Boundary Fill Algorithm (Overview)
Boundary Fill Algorithm (Overview)

Starts from an interior point and fills until it Requires interior point, fill color, and boundary
reaches boundary color. color.
07
Boundary Fill – 4-Connected
Boundary Fill – 4-Connected
1 2 3

Neighbor Usage Boundary Stopping Shape Suitability


Uses left, right, top, bottom Recursive fill stops at boundary Suitable for closed shapes.
neighbors. color.
08
Boundary Fill – 8-Connected
Boundary Fill – 8-Connected

Adds diagonal neighbors for full coverage. Used for irregular or rounded shapes.
09
Flood Fill Algorithm (Overview)
Flood Fill Algorithm
(Overview)
1 Non-uniform Boundary
Used when boundary is not uniform.

2 Interior Color Replacement


Replaces interior color instead of searching boundary.

3 Loose Regions
Suitable for loose or open regions.
10
Flood Fill – 4-Connected
Flood Fill – 4-Connected

Checks and fills up, down, left, right. Recursively replaces matching interior color.
11
Flood Fill – 8-Connected
Flood Fill – 8-Connected
1 Includes diagonal neighbors.

2 Fills complex regions completely.


12
Inside-Outside Test (Polygon Filling)
Inside-Outside Test (Polygon Filling)

Determines whether point is inside or outside Used in scanline algorithms.


polygon.
13
Odd-Even Rule
Odd-Even Rule
1 Draw line from point to edge of canvas.

2 Count edge intersections:\


Odd = Inside, Even = Outside.
14
Nonzero Winding Number Rule
Nonzero Winding Number Rule

Assign +1 for upward, -1 for downward edges. Sum the values:\


Non-zero = Inside.
Summary

Algorithm Based On Used For Types

Seed Fill Pixel Color Interior Fill 4 & 8-connected

Boundary Fill Boundary Color Enclosed Fill 4 & 8-connected

Flood Fill Interior Color Loose Fill 4 & 8-connected


17
Boundary Fill – 4-Connected (Code)
Boundary Fill – 4-
Connected (Code)
void BoundaryFill4(int x, int y, int b_color, int fill_color) { int
current = getpixel(x, y); if (current != b_color && current !=
fill_color) { putpixel(x, y, fill_color); BoundaryFill4(x + 1,
y, b_color, fill_color); BoundaryFill4(x - 1, y, b_color, fill_color);
BoundaryFill4(x, y + 1, b_color, fill_color); BoundaryFill4(x,
y - 1, b_color, fill_color); }}
18
Boundary Fill – 8-Connected (Code)
Boundary Fill – 8-Connected (Code)
void BoundaryFill8(int x, int y, int b_color, int fill_color) { int current = getpixel(x, y); if (current !=
b_color && current != fill_color) { putpixel(x, y, fill_color); BoundaryFill8(x + 1, y, b_color, fill_color);
BoundaryFill8(x - 1, y, b_color, fill_color); BoundaryFill8(x, y + 1, b_color, fill_color);
BoundaryFill8(x, y - 1, b_color, fill_color); BoundaryFill8(x + 1, y + 1, b_color, fill_color);
BoundaryFill8(x - 1, y - 1, b_color, fill_color); BoundaryFill8(x + 1, y - 1, b_color, fill_color);
BoundaryFill8(x - 1, y + 1, b_color, fill_color); }}
19
Flood Fill – 4-Connected (Code)
Flood Fill – 4-Connected
(Code)
void FloodFill4(int x, int y, int fill_color, int old_color) { int current
= getpixel(x, y); if (current == old_color) { putpixel(x, y,
fill_color); FloodFill4(x + 1, y, fill_color, old_color);
FloodFill4(x - 1, y, fill_color, old_color); FloodFill4(x, y + 1,
fill_color, old_color); FloodFill4(x, y - 1, fill_color,
old_color); }}
20
Flood Fill – 8-Connected (Code)
Flood Fill – 8-Connected
(Code)
void FloodFill8(int x, int y, int fill_color, int old_color) { int current
= getpixel(x, y); if (current == old_color) { putpixel(x, y,
fill_color); FloodFill8(x + 1, y, fill_color, old_color);
FloodFill8(x - 1, y, fill_color, old_color); FloodFill8(x, y + 1,
fill_color, old_color); FloodFill8(x, y - 1, fill_color, old_color);
FloodFill8(x + 1, y + 1, fill_color, old_color); FloodFill8(x - 1, y
- 1, fill_color, old_color); FloodFill8(x + 1, y - 1, fill_color,
old_color); FloodFill8(x - 1, y + 1, fill_color, old_color); }}
Thank You

You might also like