0% found this document useful (0 votes)
16 views20 pages

Area Filling Algorithms With Code

The document discusses area filling algorithms used in computer graphics, including Seed Fill, Boundary Fill, and Flood Fill, which are employed to color or paint regions. It outlines the differences between 4-connected and 8-connected methods for each algorithm, detailing their applications and recursive processes. Additionally, it covers polygon filling techniques like the Odd-Even Rule and Nonzero Winding Number Rule, along with code implementations for each algorithm.

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)
16 views20 pages

Area Filling Algorithms With Code

The document discusses area filling algorithms used in computer graphics, including Seed Fill, Boundary Fill, and Flood Fill, which are employed to color or paint regions. It outlines the differences between 4-connected and 8-connected methods for each algorithm, detailing their applications and recursive processes. Additionally, it covers polygon filling techniques like the Odd-Even Rule and Nonzero Winding Number Rule, along with code implementations for each algorithm.

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/ 20

Area Filling Algorithms

Seed Fill | Boundary Fill | Flood Fill


Prepared by: Roll No. 5, 6, 7
BCA 5th Semester
Subject: Computer Graphics
What is Area Filling?
• - Area filling is used to color or paint regions in
graphics.
• - Two strategies: boundary-based and interior-
based filling.
• - Used in drawing tools, games, and image
processing.
Seed Filling Algorithm (Overview)
• - Starts from a seed point inside the region.
• - Replaces specific color pixels outward until
condition fails.
• - Two types: 4-connected and 8-connected.
Seed Fill – 4-Connected Algorithm
• - Uses 4 neighbors (left, right, top, bottom).
• - Recursively replaces default color with fill
color.
• - Stops at boundary or mismatch.
Seed Fill – 8-Connected Algorithm
• - Includes diagonal neighbors.
• - Handles curved/complex regions better.
• - More complete than 4-connected.
Boundary Fill Algorithm (Overview)
• - Starts from an interior point and fills until it
reaches boundary color.
• - Requires interior point, fill color, and
boundary color.
Boundary Fill – 4-Connected
• - Uses left, right, top, bottom neighbors.
• - Recursive fill stops at boundary color.
• - Suitable for closed shapes.
Boundary Fill – 8-Connected
• - Adds diagonal neighbors for full coverage.
• - Used for irregular or rounded shapes.
Flood Fill Algorithm (Overview)
• - Used when boundary is not uniform.
• - Replaces interior color instead of searching
boundary.
• - Suitable for loose or open regions.
Flood Fill – 4-Connected
• - Checks and fills up, down, left, right.
• - Recursively replaces matching interior color.
Flood Fill – 8-Connected
• - Includes diagonal neighbors.
• - Fills complex regions completely.
Inside-Outside Test (Polygon Filling)
• - Determines whether point is inside or
outside polygon.
• - Used in scanline algorithms.
Odd-Even Rule
• - Draw line from point to edge of canvas.
• - Count edge intersections:
• Odd = Inside, Even = Outside.
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
Thank You
• Presented by:
• Roll No: 5, 6, 7
• Subject: Computer Graphics
• Topic: Area Filling Algorithms
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);
• }
• }
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);
• }
• }
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);
• }
• }
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);
• }
• }

You might also like