Region growing¶
| Fact | Value |
|---|---|
| Also called | Seeded region growing, Flood fill segmentation |
| Status | Implemented and tested |
| Family | Segmentation and regions |
| Engine | Browser |
| Type | Nonlinear, spatial, connected flood from a seed |
| Output | Mask |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/segmentation/regions.ts, regionGrowingFilter |
| Operator code | web/src/core/filters/segmentation/regions.ts, growRegion |
Overview¶
Region growing starts from one pixel, the seed, and spreads to the neighbors that look like it. It stops where the image becomes too different from the seed. The result is a mask of one connected area, such as an object or a background.
How it works¶
- Find the seed pixel from its position.
- Mark every pixel whose value is within the tolerance of the seed's value.
- Keep only the marked pixels that connect to the seed through marked pixels.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(s\): The seed pixel
- \(Y\): The brightness
- \(T\): The tolerance
s is the seed pixel and Y the brightness. A pixel joins the region when it matches the seed and a path of matching pixels joins it to the seed. Each step of the path goes to one of the 4 or 8 neighbors. This is how skimage.segmentation.flood grows a region. It is also the region growing with a fixed seed value that Gonzalez and Woods describe. With the color measure, the test is the largest of the three channel differences. The seed is at a percent of the width and height, rounded down to a pixel, so it stays on the same spot when the image is resized.
The tolerance trades holes against leaks. A pixel inside the object is left out when noise moves it more than the tolerance from the seed. A pixel outside joins when the tolerance reaches across the step between object and background. A good tolerance is larger than the noise and smaller than that step.
Kernel or operator¶
The Inspector shows the seed, the match test and the growth rule with the current settings.
Algorithm¶
- Find the seed pixel from its position in percent.
- Mark every pixel that matches the seed within the tolerance.
- Keep only the marked pixels connected to the seed, and make them white.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Seed x seedX |
50 | 0 to 100 % | The seed's position across the image, in percent of the width. |
Seed y seedY |
50 | 0 to 100 % | The seed's position down the image, in percent of the height. |
Tolerance tolerance |
20 | 0 to 255 | How far a pixel's value may be from the seed's and still join the region. |
Compare by measure |
Brightness | Brightness, Color | Compare the brightness of the pixels, or their red, green and blue values. |
Neighbors connectivity |
8 (sides and corners) | 8 (sides and corners), 4 (sides only) | Which neighbors the region grows into. |
Implementation¶
regionGrowingFilter in web/src/core/filters/segmentation/regions.ts marks the matching pixels and keeps the component of the seed with labelComponents.
Worked example¶
| Tolerance | Region area (pixels) |
|---|---|
| 20 | 1213 |
| 40 | 1550 |
| 80 | 1567 |
| 120 | 1595 |
| 160 | 1634 |
| 200 | 5286 |
The test disks with Gaussian noise of sigma 12 (seed 7), 160 by 160 pixels, and the seed at 25 % of the width and 62.5 % of the height, the center of the largest disk. Brightness and 8 neighbors are the defaults. A small tolerance leaves noisy pixels out, so the region has holes. Once the tolerance covers the noise, the region is the disk, about 1590 pixels. The disk is 220 and the background 30, so when the tolerance nears that gap of 190, noisy background pixels start to match, and the region leaks into the background.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels.
Artifacts and limitations¶
Limitations
- Compares with the seed only, so slow changes of brightness across an area can stop it early.
- A single noisy seed pixel can give a poor region. Smooth the image first.
Artifacts
- Holes where noise pushes pixels past the tolerance.
- Leaks through thin gaps in a boundary.
Tests¶
The fixture cases compare every pixel with skimage.segmentation.flood on the brightness, with 4 and 8 neighbors. For the color measure, they use the same flood on the largest channel difference. No brightness lies on the tolerance, so rounding cannot move a pixel across it. Unit tests check the seed position and that a matching area not connected to the seed stays out.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/segmentation/segmentation.test.ts
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 10, region growing.
- scikit-image documentation, skimage.segmentation.flood. https://scikit-image.org/docs/stable/api/skimage.segmentation.html