Flood Fill: Flood Fill: Exploring Computer Vision's Dynamic Terrain
By Fouad Sabry
()
About this ebook
What is Flood Fill
Flood fill, also called seed fill, is a flooding algorithm that determines and alters the area connected to a given node in a multi-dimensional array with some matching attribute. It is used in the "bucket" fill tool of paint programs to fill connected, similarly-colored areas with a different color, and in games such as Go and Minesweeper for determining which pieces are cleared. A variant called boundary fill uses the same algorithms but is defined as the area connected to a given node that does not have a particular attribute.
How you will benefit
(I) Insights, and validations about the following topics:
Chapter 1: Flood fill
Chapter 2: Scanline rendering
Chapter 3: Depth-first search
Chapter 4: Quadtree
Chapter 5: Graph traversal
Chapter 6: Connected-component labeling
Chapter 7: Watershed (image processing)
Chapter 8: Maze-solving algorithm
Chapter 9: Ray casting
Chapter 10: Box blur
(II) Answering the public top questions about flood fill.
(III) Real world examples for the usage of flood fill in many fields.
Who this book is for
Professionals, undergraduate and graduate students, enthusiasts, hobbyists, and those who want to go beyond basic knowledge or information for any kind of Flood Fill.
Read more from Fouad Sabry
Related to Flood Fill
Titles in the series (100)
Image Histogram: Unveiling Visual Insights, Exploring the Depths of Image Histograms in Computer Vision Rating: 0 out of 5 stars0 ratingsFilter Bank: Insights into Computer Vision's Filter Bank Techniques Rating: 0 out of 5 stars0 ratingsInpainting: Bridging Gaps in Computer Vision Rating: 0 out of 5 stars0 ratingsColor Matching Function: Understanding Spectral Sensitivity in Computer Vision Rating: 0 out of 5 stars0 ratingsRetinex: Unveiling the Secrets of Computational Vision with Retinex Rating: 0 out of 5 stars0 ratingsComputer Vision: Exploring the Depths of Computer Vision Rating: 0 out of 5 stars0 ratingsUnderwater Computer Vision: Exploring the Depths of Computer Vision Beneath the Waves Rating: 0 out of 5 stars0 ratingsComputer Stereo Vision: Exploring Depth Perception in Computer Vision Rating: 0 out of 5 stars0 ratingsColor Management System: Optimizing Visual Perception in Digital Environments Rating: 0 out of 5 stars0 ratingsAnisotropic Diffusion: Enhancing Image Analysis Through Anisotropic Diffusion Rating: 0 out of 5 stars0 ratingsHistogram Equalization: Enhancing Image Contrast for Enhanced Visual Perception Rating: 0 out of 5 stars0 ratingsNoise Reduction: Enhancing Clarity, Advanced Techniques for Noise Reduction in Computer Vision Rating: 0 out of 5 stars0 ratingsJoint Photographic Experts Group: Unlocking the Power of Visual Data with the JPEG Standard Rating: 0 out of 5 stars0 ratingsTone Mapping: Tone Mapping: Illuminating Perspectives in Computer Vision Rating: 0 out of 5 stars0 ratingsGamma Correction: Enhancing Visual Clarity in Computer Vision: The Gamma Correction Technique Rating: 0 out of 5 stars0 ratingsHomography: Homography: Transformations in Computer Vision Rating: 0 out of 5 stars0 ratingsAffine Transformation: Unlocking Visual Perspectives: Exploring Affine Transformation in Computer Vision Rating: 0 out of 5 stars0 ratingsRadon Transform: Unveiling Hidden Patterns in Visual Data Rating: 0 out of 5 stars0 ratingsLevel Set Method: Advancing Computer Vision, Exploring the Level Set Method Rating: 0 out of 5 stars0 ratingsAdaptive Filter: Enhancing Computer Vision Through Adaptive Filtering Rating: 0 out of 5 stars0 ratingsHough Transform: Unveiling the Magic of Hough Transform in Computer Vision Rating: 0 out of 5 stars0 ratingsVisual Perception: Insights into Computational Visual Processing Rating: 0 out of 5 stars0 ratingsHuman Visual System Model: Understanding Perception and Processing Rating: 0 out of 5 stars0 ratingsImage Compression: Efficient Techniques for Visual Data Optimization Rating: 0 out of 5 stars0 ratingsColor Space: Exploring the Spectrum of Computer Vision Rating: 0 out of 5 stars0 ratingsColor Profile: Exploring Visual Perception and Analysis in Computer Vision Rating: 0 out of 5 stars0 ratingsColor Appearance Model: Understanding Perception and Representation in Computer Vision Rating: 0 out of 5 stars0 ratingsHadamard Transform: Unveiling the Power of Hadamard Transform in Computer Vision Rating: 0 out of 5 stars0 ratingsLeast Squares: Optimization Techniques for Computer Vision: Least Squares Methods Rating: 0 out of 5 stars0 ratingsBundle Adjustment: Optimizing Visual Data for Precise Reconstruction Rating: 0 out of 5 stars0 ratings
Related ebooks
Breadth First Search: Fundamentals and Applications Rating: 0 out of 5 stars0 ratingsBackpropagation: Fundamentals and Applications for Preparing Data for Training in Deep Learning Rating: 0 out of 5 stars0 ratingsPerceptrons: Fundamentals and Applications for The Neural Building Block Rating: 0 out of 5 stars0 ratingsHidden Line Removal: Unveiling the Invisible: Secrets of Computer Vision Rating: 0 out of 5 stars0 ratingsDepth First Search: Fundamentals and Applications Rating: 0 out of 5 stars0 ratingsA Star: Fundamentals and Applications Rating: 0 out of 5 stars0 ratingsADVANCED DATA STRUCTURES FOR ALGORITHMS: Mastering Complex Data Structures for Algorithmic Problem-Solving (2024) Rating: 0 out of 5 stars0 ratingsData Structures and Algorithms in Swift: Implement Stacks, Queues, Dictionaries, and Lists in Your Apps Rating: 0 out of 5 stars0 ratingsLine Drawing Algorithm: Mastering Techniques for Precision Image Rendering Rating: 0 out of 5 stars0 ratingsScanline Rendering: Exploring Visual Realism Through Scanline Rendering Techniques Rating: 0 out of 5 stars0 ratingsMesh Generation: Advances and Applications in Computer Vision Mesh Generation Rating: 0 out of 5 stars0 ratingsSupport Vector Machine: Fundamentals and Applications Rating: 0 out of 5 stars0 ratingsQuadtree: Exploring Hierarchical Data Structures for Image Analysis Rating: 0 out of 5 stars0 ratingsBinary Space Partitioning: Exploring Binary Space Partitioning: Foundations and Applications in Computer Vision Rating: 0 out of 5 stars0 ratingsBresenham Line Algorithm: Efficient Pixel-Perfect Line Rendering for Computer Vision Rating: 0 out of 5 stars0 ratingsBilinear Interpolation: Enhancing Image Resolution and Clarity through Bilinear Interpolation Rating: 0 out of 5 stars0 ratingsLevel Set Method: Advancing Computer Vision, Exploring the Level Set Method Rating: 0 out of 5 stars0 ratingsRandom Sample Consensus: Robust Estimation in Computer Vision Rating: 0 out of 5 stars0 ratingsRadial Basis Networks: Fundamentals and Applications for The Activation Functions of Artificial Neural Networks Rating: 0 out of 5 stars0 ratingsGeometric Hashing: Efficient Algorithms for Image Recognition and Matching Rating: 0 out of 5 stars0 ratingsConvolutional Neural Networks: Fundamentals and Applications for Analyzing Visual Imagery Rating: 0 out of 5 stars0 ratingsMachine Learning - Advanced Concepts Rating: 0 out of 5 stars0 ratingsMATLAB for Beginners: A Gentle Approach Rating: 0 out of 5 stars0 ratingsNumerical Analysis of Wavelet Methods Rating: 0 out of 5 stars0 ratingsScale Invariant Feature Transform: Unveiling the Power of Scale Invariant Feature Transform in Computer Vision Rating: 0 out of 5 stars0 ratingsNell: An SVG Drawing Language Rating: 0 out of 5 stars0 ratingsMATLAB for Beginners: A Gentle Approach - Revised Edition Rating: 3 out of 5 stars3/5Spatiotemporal Data Analysis Rating: 3 out of 5 stars3/5Advanced C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsDesign And Analysis Of Algorithm Rating: 0 out of 5 stars0 ratings
Intelligence (AI) & Semantics For You
101 Midjourney Prompt Secrets Rating: 3 out of 5 stars3/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5The Secrets of ChatGPT Prompt Engineering for Non-Developers Rating: 5 out of 5 stars5/5ChatGPT For Dummies Rating: 0 out of 5 stars0 ratingsCreating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Killer ChatGPT Prompts: Harness the Power of AI for Success and Profit Rating: 2 out of 5 stars2/5AI for Educators: AI for Educators Rating: 5 out of 5 stars5/5ChatGPT Rating: 3 out of 5 stars3/5A Quickstart Guide To Becoming A ChatGPT Millionaire: The ChatGPT Book For Beginners (Lazy Money Series®) Rating: 4 out of 5 stars4/5Chat-GPT Income Ideas: Pioneering Monetization Concepts Utilizing Conversational AI for Profitable Ventures Rating: 4 out of 5 stars4/5ChatGPT Ultimate User Guide - How to Make Money Online Faster and More Precise Using AI Technology Rating: 0 out of 5 stars0 ratings10 Great Ways to Earn Money Through Artificial Intelligence(AI) Rating: 5 out of 5 stars5/5The Business Case for AI: A Leader's Guide to AI Strategies, Best Practices & Real-World Applications Rating: 0 out of 5 stars0 ratingsChatGPT For Fiction Writing: AI for Authors Rating: 5 out of 5 stars5/5Artificial Intelligence: A Guide for Thinking Humans Rating: 4 out of 5 stars4/5What Makes Us Human: An Artificial Intelligence Answers Life's Biggest Questions Rating: 5 out of 5 stars5/5TensorFlow in 1 Day: Make your own Neural Network Rating: 4 out of 5 stars4/5Dancing with Qubits: How quantum computing works and how it can change the world Rating: 5 out of 5 stars5/5Summary of Super-Intelligence From Nick Bostrom Rating: 5 out of 5 stars5/5
Reviews for Flood Fill
0 ratings0 reviews
Book preview
Flood Fill - Fouad Sabry
Chapter 1: Flood fill
Flood fill, also known as seed fill, is a flooding algorithm that chooses and modifies the region in a multidimensional array associated to a specific node with a particular attribute. It is used in games like Go and Minesweeper to determine which pieces are cleared as well as in paint applications' bucket
fill tool to fill connected, similarly colored areas with a distinct hue. The region connected to a given node but lacking a specific attribute is what is meant by the variation known as border fill, which employs the same techniques.
Keep in mind that flood filling will miss certain pixels in more acute corners, making it unsuitable for drawing filled polygons. Instead, check the Nonzero Rule and the Even-Odd Rule.
Three variables are required by the classic flood-fill algorithm: a start node, a target color, and a replacement color. The method switches to the replacement color for every node in the array that is connected to the start node by a path that is the target color. Instead of the target color, a border color would be provided for a boundary-fill.
Instead, two routines will be provided in the following descriptions in order to generalize the method in the usual manner. Among these are Set, which fills a pixel or node, and Inside, which returns true for unfilled points that, based on their color, would be inside the filled area. Once Set has been called on a node, it must leave the Inside.
There are two versions depending on whether we count nodes touching at the corners as connected or not: eight-way and four-way, respectively.
Following is the earliest known four-way flood-fill implementation that is implicitly stack-based:
Flood-fill (node):
1. If node is not Inside return.
2. Set the node
3. Perform Flood-fill one step to the south of node.
4. Perform Flood-fill one step to the north of node
5. Perform Flood-fill one step to the west of node
6. Perform Flood-fill one step to the east of node
7. Return.
In languages and situations where stack space is extremely constrained, the implementation of the technique used above is simple to grasp but unworkable (e.g. Microcontrollers).
A stack overflow is avoided by moving the recursion into a data structure, such as a stack or queue. The choice of data structure affects the proliferation pattern, but it is similar to the simple recursive method in that it pushes the nodes into a stack or queue for consumption rather than making recursive calls:
Flood-fill (node):
1. Set Q to the empty queue or stack.
2. Add node to the end of Q.
3. While Q is not empty:
4. Set n equal to the first element of Q.
5. Remove first element from Q.
6. If n is Inside:
Set the n
Add the node to the west of n to the end of Q.
Add the node to the east of n to the end of Q.
Add the node to the north of n to the end of Q.
Add the node to the south of n to the end of Q.
7. Continue looping until Q is exhausted.
8. Return.
Before adding a node to the stack or queue, determine and set its pixel color to minimize the size of the stack or queue.
Utilize a loop to move in an east-west direction while queuing pixels above and below (making it similar to the span filling algorithms, below).
To provide out-of-order processors more opportunities to parallelize, interleave two or more copies of the code with additional stacks and queues.
Use several threads, ideally with slightly different visitation schedules so they don't congregate in one place.
Straightforward method that is simple to create bug-free.
memory intensive, especially when using a stack.
tests the most filled pixels four times in total.
Pattern filling is not possible since it needs the results of pixel tests to change.
Access pattern for the queuing variation is not cache-friendly.
difficult to optimize for bitplanes or multi-pixel words.
Working largely with spans, a row with constant y, allows for further optimization. The first published complete example operates according to the following fundamental tenet:.
Fill left and right after a seed point. Keep track of the leftmost and rightmost filled points, lx and rx, respectively. This establishes the range.
Search for more seed points by scanning from lx to rx above and below the current seed point.
The scan process is optimized so that only the seed points at the beginning of the following span must be restarted. A queue explores spans first, while a stack investigates spans first in terms of depth.
Despite checking the most filled pixels three times in total, this approach is the most common in terms of implementations and citations.
fn fill(x, y):
if not Inside(x, y) then return
let s = new empty stack or queue
Add (x, y) to s
while s is not empty:
Remove an (x, y) from s
let lx = x
while Inside(lx - 1, y):
Set(lx - 1, y)
lx = lx - 1
while Inside(x, y):
Set(x, y)
x = x + 1
scan(lx, x - 1, y + 1, s)
scan(lx, x - 1, y - 1, s)
fn scan(lx, rx, y, s):
let span_added = false
for x in lx .. rx:
if not Inside(x, y):
span_added = false
else if not span_added:
Add (x, y) to s
span_added = true
The following improvements were made over time:
A fresh scan wouldn't need to be queued if it were wholly within a grandparent span because it would only detect filled pixels.
Furthermore, only the overhangs (U-turns and W-turns) must be scanned when a new scan crosses a grandparent span.
You can fill up while looking for seeds.
fn fill(x, y):
if not Inside(x, y) then return
let s = new empty queue or stack
Add (x, x, y, 1) to s
Add (x, x, y - 1, -1) to s
while s is not empty:
Remove an (x1, x2, y, dy) from s
let x = x1
if Inside(x, y):
while Inside(x - 1, y):
Set(x - 1, y)
x = x - 1
if x < x1:
Add (x, x1-1, y-dy, -dy) to s
while x1 <= x2:
while Inside(x1, y):
Set(x1, y)
x1 = x1 + 1
Add (x, x1 - 1, y+dy, dy) to s
if x1 - 1 > x2:
Add (x2 + 1, x1 - 1, y-dy, -dy) to s
x1 = x1 + 1
while x1 < x2 and not Inside(x1, y):
x1 = x1 + 1
x = x1
quicker than the pixel-recursive technique by 2–8 times.
Friendly to cache and bitplane access patterns.
Rather than