Convex hull¶
| Fact | Value |
|---|---|
| Also called | Convex hull per object |
| Status | Implemented and tested |
| Family | Morphological filters |
| Engine | Browser |
| Type | Nonlinear, spatial, convex hull of each component |
| Output | Mask |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/morphology/binary.ts, convexHullFilter |
| Operator code | web/src/core/filters/morphology/binary.ts, convexHullObjects |
| Channels | Brightness only, RGB |
Overview¶
The convex hull replaces every white object with the smallest convex shape that contains it. Dents and holes fill in, and separate objects get separate hulls.
How it works¶
- Find the separate objects.
- Compute the convex hull of each object's pixels.
- Fill every pixel whose center lies inside a hull or on its border.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(C_i\): The objects
- \(\\operatorname{conv}\): The convex hull
C_i are the objects, the connected parts of the foreground. The hull of each is computed from the midpoints of the edges of its pixels, and every pixel whose center lies inside the hull or on its border becomes foreground. This matches skimage.morphology.convex_hull_object.
A shape is convex when the straight line between any two of its points stays inside it. The hull of an object is the smallest convex shape around it. On a pixel grid, the hull is computed from the midpoints of the pixel edges and then rasterized by pixel centers, as scikit-image does.
Kernel or operator¶
There is no kernel. The Inspector lists the components and the hulls.
Algorithm¶
- Make the image binary and label its objects.
- For each object, find the convex hull of its pixel edge midpoints.
- Fill every pixel whose center lies inside or on the hull.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Neighbors connectivity |
8 neighbors | 8 neighbors, 4 neighbors | Which foreground pixels count as one object. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
convexHullObjects in web/src/core/filters/morphology/binary.ts labels the objects, computes each hull with the monotone chain, and fills it. It is a global filter, so it 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. Values at or above 128 count as white, and the result is 255 or 0.
Worked example¶
| Row | Input | Result |
|---|---|---|
| 0 | 1 0 0 0 0 0 0 0 0 0 |
1 0 0 0 0 0 0 0 0 0 |
| 1 | 0 0 0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 0 0 |
| 2 | 0 1 1 1 1 1 1 0 0 0 |
0 1 1 1 1 1 1 0 0 0 |
| 3 | 0 1 1 1 1 1 1 0 0 0 |
0 1 1 1 1 1 1 0 0 0 |
| 4 | 0 1 1 1 1 1 1 0 0 0 |
0 1 1 1 1 1 1 0 0 0 |
| 5 | 0 0 0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 0 0 |
| 6 | 0 0 1 0 0 0 0 0 0 0 |
0 0 1 0 0 0 0 0 0 0 |
| 7 | 0 0 1 0 0 0 0 0 0 0 |
0 0 1 1 0 0 0 0 0 0 |
| 8 | 0 0 1 1 1 0 0 0 0 0 |
0 0 1 1 1 0 0 0 0 0 |
A small binary image, 1 for white and 0 for black. The L gains the pixel in its inner corner, the only new pixel center inside the hull of its pixels. The bar and the isolated pixel are already convex.
Complexity¶
- Time: \(O(N log N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. The hull of an object of m pixels costs O(m log m).
Artifacts and limitations¶
Limitations
- Hulls of nearby objects may overlap.
Artifacts
- Overlapping hulls join objects in the result.
Tests¶
The reference is skimage.morphology.convex_hull_object. The cases cover 4 and 8 neighbors.
References¶
- Soille, P. Morphological Image Analysis, 2nd edition. Springer, 2004. DOI 10.1007/978-3-662-05088-0.
- scikit-image documentation, skimage.morphology.convex_hull_object. https://scikit-image.org/docs/stable/api/skimage.morphology.html#skimage.morphology.convex_hull_object