Chan-Vese segmentation¶
| Fact | Value |
|---|---|
| Also called | Active contours without edges, Chan-Vese |
| Status | Implemented and tested |
| Family | Segmentation and regions |
| Engine | Science engine |
| Type | Nonlinear, iterative, level set evolution |
| Output | Labels |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/contours.py, chan_vese_filter |
| Operator code | engine/src/pixelnexus_engine/filters/contours.py, chan_vese_representation |
| Packages | scikit-image |
Overview¶
Chan-Vese segmentation splits the image into two phases. Each phase should be as even in brightness as it can be, and the boundary between them as short as it can be. It never looks for edges. So it can follow a border that is soft, noisy or broken, where edge detectors give up. The two phases go to the Features panel with their area, centroid and mean brightness, and are drawn over the image in their label colors. Click a row number in the panel to make a phase the selection. The filter runs in the PixelNexus engine, with scikit-image.
How it works¶
- Scale the luma from 0 to 1 and start the level set.
- Find the mean luma of each phase.
- Move the level set so each pixel leans to the phase with the closer mean, and the boundary stays short.
- Stop when the level set barely changes, or after the most steps.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(\phi\): The level set, above 0 in phase 1
- \(c_1, c_2\): The mean luma of each phase
- \(\mu\): The weight of the boundary length
- \(\lambda_1, \lambda_2\): The weights of the two phases
- \(Y\): The luma, from 0 to 1
The level set phi has one value per pixel. Phase 1 is where phi is above 0, phase 2 is the rest, and the boundary is where phi is 0. The mean luma Y of the two phases is c1 and c2. The energy F adds the length of the boundary, times mu, to how far each pixel is from the mean of its phase, squared. Each step finds c1 and c2, then moves phi down the slope of F. A pixel closer to c1 than to c2 is pushed into phase 1, while the length term keeps the boundary smooth. No step looks at edges, so the boundary can cross a soft or broken border. scikit-image follows the scheme of Getreuer. It leaves out the area term of the paper, and it does not reset phi to a distance during the steps.
Chan and Vese wrote the boundary as the zero level of a function phi. The boundary can then split and merge without any extra work, so one start can find many objects. Their energy is a simple case of the Mumford-Shah model, where each phase is a flat color.
Each step has two parts. First it finds the two means. Then it moves phi so that each pixel leans toward the phase with the closer mean. The length term mu works against small wiggles and specks.
Kernel or operator¶
There is no kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Phases | Phases, Boundaries over the image, Mean color of each phase, Level set | The two phases as a label map, drawn over the image and listed in the Features panel. Or the boundary in yellow over the image, or each phase filled with its mean color. Or the final level set as gray, with 0 at middle gray. |
Length weight mu |
0.25 | 0 to 2 | The weight mu of the length of the boundary. scikit-image uses 0.25. |
Phase 1 weight lambda1 |
1 | 0 to 5 | How much an uneven phase 1 costs, lambda 1. scikit-image uses 1. |
Phase 2 weight lambda2 |
1 | 0 to 5 | How much an uneven phase 2 costs, lambda 2. scikit-image uses 1. |
Start init |
Checkerboard | Checkerboard, Large disk, Small disk | The starting level set from scikit-image. The checkerboard has squares of 5 pixels. The large disk spans the shorter side of the image, the small disk half of it. |
Iterations iterations |
500 | 1 to 2000 | The most steps to take. scikit-image uses 500. |
Tolerance tolerance |
0.001 | 0 to 0.1 | The level set stops when its root mean square change in one step is at most this. scikit-image uses 0.001. |
Time step dt |
0.5 | 0.01 to 2 | The size of each step, delta t. scikit-image uses 0.5. |
Implementation¶
chan_vese_filter in engine/src/pixelnexus_engine/filters/contours.py calls skimage.segmentation.chan_vese on the luma from 0 to 1, and asks for the final level set. scikit-image scales the image to fill 0 to 1 first. It follows the scheme of Getreuer, leaves out the area term of the paper, and does not reset phi to a distance during the steps. It stops when the root mean square change of phi in one step is at most the tolerance, or after the most steps.
The phases output is a label map, with phase 1 (phi above 0) as label 1 and the rest as label 2. Which phase is the object depends on the start. The level set output shows phi with 0 at middle gray, scaled by its largest absolute value. See the science engine for how label maps travel.
Worked example¶
| Noise sigma | Length weight mu | Tolerance | Parts of phase 1 | Overlap |
|---|---|---|---|---|
| 10 | 0 | 0.001 | 378 | 0.261 |
| 10 | 0.1 | 0.001 | 2 | 0.987 |
| 10 | 0.25 | 0.001 | 2 | 0.985 |
| 10 | 1 | 0.001 | 61 | 0.856 |
| 10 | 1 | 0.0001 | 2 | 0.957 |
| 30 | 0 | 0.001 | 182 | 0.230 |
| 30 | 0.1 | 0.001 | 2 | 0.964 |
| 30 | 0.25 | 0.001 | 2 | 0.966 |
| 30 | 1 | 0.001 | 81 | 0.745 |
| 30 | 1 | 0.0001 | 2 | 0.903 |
The image of the figure, with two objects, and the other defaults. Phase 1 should be the disk and the square, 2 parts. The parts are 8-connected. The overlap is the area of phase 1 and both objects together divided by the area of either.
With the default length weight, phase 1 is the disk and the square, 2 parts, even with noise of sigma 30. With no length weight, every noisy pixel can switch on its own, and phase 1 breaks into hundreds of parts.
A length weight of 1 looks worse than 0.25, but the cause is the stop rule. A larger mu slows each step, so at noise sigma 10 the change falls below the tolerance after 47 steps, while small squares of the checkerboard start are still left. With a tolerance of 0.0001, phase 1 is 2 parts again.
Complexity¶
- Time: \(O(N K)\)
- Memory: \(O(N)\)
N is the number of pixels and K the number of steps.
Artifacts and limitations¶
Limitations
- Only two phases, so it suits images with one kind of object on one background.
- The two phases must differ in mean brightness.
- Slow for large images at the default steps.
Artifacts
- Small specks when the length weight is low.
- Which phase is the object depends on the start.
Tests¶
The level set must be scikit-image's on the luma. On a noisy disk, phase 1 must be exactly the disk, and the table must say 2 phases. The level set output must be at or above middle gray where phi is above 0. The boundaries must be those of scikit-image's mark_boundaries. The representation must have its four stages.
References¶
- Chan, T. F., and Vese, L. A. Active contours without edges. IEEE Transactions on Image Processing 10(2), 266 to 277, 2001. DOI 10.1109/83.902291.
- Getreuer, P. Chan-Vese segmentation. Image Processing On Line 2, 214 to 224, 2012. DOI 10.5201/ipol.2012.g-cv.
- scikit-image documentation, skimage.segmentation.chan_vese.