Flood Fill
Grow one connected region from a seed pixel, making it the canonical seeded region-growing primitive.
Segmentation & edges is nested under Foundations , so the broader pipeline usually still applies here.
Interactive playground
Tweak the operator or scene live so the article connects to an immediate visual result.
Flood fill
Pick a seed region and expand through neighbors that still belong to the same region class.
Region map
Click to move the seedFilled region
96 × 96 live previewClick the source image to move the seed and watch how the reachable region changes instantly.
Seed position
(24, 28) in the low-resolution region map.
Family
Foundations -> Segmentation & edges
Turn raw pixels into masks, boundaries, and simpler structural signals.
Builds on
2 topics
Read these first if you want the surrounding pipeline context.
Unlocks
1 next topic
Use these follow-ups when you want to keep turning the image-processing pipeline forward.
Learning paths
1
This topic appears in curated graphics progressions so the next step is obvious.
Choose this over that
Region growing vs connected-component labeling
Both topics reason about connected regions, but flood fill starts from one seed while component labeling partitions everything.
Flood Fill
Choose this when: You have one seed and want to grow exactly that region.
Choose something else when: The whole image needs a full partition into region IDs.
Connected-Components Labeling
Choose this when: Every connected region should receive a label, size, or later measurement.
Choose something else when: Only one local region is relevant at a time.
Distance Transform
Choose this when: The question is not membership, but distance to boundaries or background.
Choose something else when: Simple reachability already solves the problem.
Problem
Sometimes you do not want every object in the mask. You want the region that contains one chosen seed, like a bucket fill tool or a seeded segmentation pass.
Intuition
Flood fill is just graph traversal on the pixel grid. Starting from one seed, you visit all neighboring pixels that satisfy the region rule and stop when the region boundary blocks expansion.
Core idea
- Choose a seed pixel.
- Use BFS or DFS over 4-neighbor or 8-neighbor connectivity.
- Only expand into pixels that match the allowed condition, such as the same label or being inside the foreground mask.
- Mark every reached pixel as belonging to the filled region.
Worked example
A paint-bucket tool in an editor starts from one click, then floods through all connected pixels that still belong to the same area. That is flood fill in its purest form.
Complexity
Flood fill is O(size of the reached region) and O(WH) in the worst case if the region spans the whole image.
When to choose it
- Choose it when the input provides a meaningful seed.
- Choose component labeling when you need all connected regions, not just one.
- Choose dilation when the goal is morphological growth of a mask rather than seeded traversal.
Key takeaways
- Flood fill is graph traversal on an image grid.
- The connectivity rule and the region-membership rule both matter.
- It is the seeded cousin of connected-components labeling.
- It shows up everywhere from paint tools to seeded segmentation and mask editing.
Practice ideas
- Implement 4-neighbor and 8-neighbor flood fill and compare the difference on diagonally touching pixels.
- Use flood fill to keep only the component that contains a chosen seed.
- Combine thresholding and flood fill to segment one object from a simple grayscale scene.
Relation to other topics
- Connected-components labeling generalizes flood fill from one seed to every region in the image.
- Thresholding often creates the binary mask flood fill expands through.
- Dilation changes the shape of the mask globally, whereas flood fill traverses an existing shape from a seed.
Build on these first
These topics supply the mental model or preceding stage that this page assumes.
Image Processing Fundamentals
Build the mental model behind blur, thresholding, edges, and morphology: pixels, neighborhoods, kernels, masks, and why local operators compose into pipelines.
Thresholding
Convert a grayscale image into a binary mask by splitting values into foreground and background.
What this enables
Once the current operator feels natural, these are the most useful follow-up jumps.
Related directions
These topics live nearby conceptually, even if they are not strict prerequisites.
Connected-Components Labeling
Turn a binary mask into object IDs so you can count, measure, filter, and track separate regions instead of raw foreground pixels.
Distance Transform
For every foreground pixel, compute how far it sits from the background or boundary so the mask gains geometric thickness information.
Dilation
Grow foreground regions in a binary mask so gaps close and thin structures get thicker.
More from Segmentation & edges
Stay in the same family when you want parallel operators built from the same mental model.
Thresholding
Convert a grayscale image into a binary mask by splitting values into foreground and background.
Connected-Components Labeling
Turn a binary mask into object IDs so you can count, measure, filter, and track separate regions instead of raw foreground pixels.
Laplacian and Laplacian of Gaussian
Use second-derivative style filters to emphasize rapid intensity change and zero crossings, often after smoothing first.
Sobel Edge Detection
Estimate local intensity gradients so boundaries become visible as bright responses.
Paths that include this topic
Follow one of these sequences if you want a guided next step instead of open-ended browsing.
Mask analysis and cleanup
Build a binary mask, explore connectivity, then repair or simplify it with morphology-aware tools.
From the blog
Pair the graphics atlas with recent writing from the broader site whenever you want a wider engineering lens.