Geodesic filtering¶
| Fact | Value |
|---|---|
| Also called | Geodesic dilation, Geodesic erosion |
| Status | Implemented and tested |
| Family | Morphological filters |
| Engine | Browser |
| Type | Nonlinear, spatial, geodesic dilation or erosion |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/morphology/reconstruction.ts, geodesicFilter |
| Operator code | web/src/core/filters/morphology/reconstruction.ts, geodesic |
| Channels | RGB, Brightness only |
Overview¶
Geodesic filtering runs a fixed number of geodesic dilation or erosion steps. The marker, the image moved down by h, grows one pixel per step but never above the image. It shows how reconstruction spreads, and it limits how far a marker may reach.
How it works¶
- Move the image down by h for dilation, or up for erosion.
- Dilate the marker with the 3 x 3 element and take the minimum with the image, or erode and take the maximum.
- Repeat for the chosen number of steps.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(J_k\): The marker after k steps
- \(N\): The 3 x 3 cross or square
J_0 is the image moved down by h, clamped below the image f. Each step dilates J with the 3 x 3 element N and takes the minimum with f. Geodesic erosion swaps dilation with erosion and minimum with maximum, starting from the image moved up by h. After enough steps, the result is the reconstruction.
Each geodesic step spreads the marker by one pixel, along paths that stay under the image. After n steps every pixel holds the largest marker value within n steps along such paths. With enough steps the result stops changing and equals the reconstruction.
Kernel or operator¶
There is no kernel. The Inspector lists the marker and the step with the current h, number of steps and connectivity.
Algorithm¶
- Build the marker, the image moved down by h for dilation or up for erosion.
- Repeat the chosen number of times. Dilate the marker with N and take the minimum with the image, or erode and take the maximum.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Method method |
By dilation (bright parts) | By dilation (bright parts), By erosion (dark parts) | Whether the marker grows up under the image or shrinks down over it. |
Height h h |
20 | 0 to 255 | The marker is the image moved down by h for dilation, or up by h for erosion. |
Steps steps |
5 | 1 to 50 | How many geodesic steps to run. |
Neighbors connectivity |
8 neighbors | 8 neighbors, 4 neighbors | Which pixels count as joined when the reconstruction spreads. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
geodesic in web/src/core/filters/morphology/reconstruction.ts repeats the dilation and the minimum. Pixels past the image edge repeat the edge, which leaves the maximum or minimum unchanged. It is a global filter. Reconstruction can reach across the whole image, so the filter always runs on the whole image in one tile, and a selection is cut out of the result. The filter runs in the browser engine through the shared filter framework in web/src/core/filters/run.ts, which handles the channel scope and alpha.
Worked example¶
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| Input | 10 | 10 | 40 | 10 | 10 | 90 | 120 | 90 | 10 | 10 |
| 1 step, h 50 | -40 | -10 | -10 | -10 | 10 | 70 | 70 | 70 | 10 | -40 |
One step of geodesic dilation from the row minus 50. Each pixel takes the largest marker value of itself and its neighbors, capped at the image. After one step the marker has spread one pixel. Values below 0 show as 0 in the image. More steps reach the reconstruction.
Complexity¶
- Time: \(O(N n)\)
- Memory: \(O(N)\)
N is the number of pixels per channel and n the number of steps.
Artifacts and limitations¶
Limitations
- Slower than reconstruction when many steps are needed.
Artifacts
- Partly restored peaks when the steps run out.
Tests¶
The reference repeats scipy.ndimage.grey_dilation or grey_erosion with the 3 x 3 cross or square and takes the minimum or maximum with the image. The cases cover both methods and both connectivities.
References¶
- Vincent, L. Morphological grayscale reconstruction in image analysis, applications and efficient algorithms. IEEE Transactions on Image Processing 2(2), 176 to 201, 1993. DOI 10.1109/83.217222.
- Soille, P. Morphological Image Analysis, 2nd edition. Springer, 2004. DOI 10.1007/978-3-662-05088-0.