Skip to content

Morphological leveling

Fact Value
Also called Leveling, Meyer leveling
Status Implemented and tested
Family Morphological filters
Engine Browser
Type Nonlinear, spatial, self-dual reconstruction from a marker
Output Image
Operator shown as algorithm (exact)
Support radius global
Code web/src/core/filters/morphology/reconstruction.ts, levelingFilter
Operator code web/src/core/filters/morphology/reconstruction.ts, leveling
Channels RGB, Brightness only

Overview

A leveling moves the image toward a marker, here a Gaussian blur of the image, while keeping every edge exactly in place. Flat zones grow and merge, but no new slope appears and no edge moves. It simplifies an image for segmentation without the blur of the marker.

Three panels: noisy bright disks, the blurred marker, and the leveling, which is smooth inside and outside the disks with sharp disk edges. Three panels: noisy bright disks, the blurred marker, and the leveling, which is smooth inside and outside the disks with sharp disk edges.
Leveling of noisy disks with a Gaussian marker of sigma 2. The marker is blurred, but the leveling keeps the disk edges sharp while it flattens the noise.

How it works

  1. Blur the image to get a marker.
  2. Let the marker grow up under bright parts of the image and shrink down over dark parts.
  3. Repeat until nothing changes.

Mathematical foundation

\[ g_{k+1} = \left(f \wedge \delta_N(g_k)\right) \vee \varepsilon_N(g_k) \]

The formula shows the default parameter values.

where

  • \(f\): The image
  • \(g_k\): The leveling after k steps
  • \(N\): The 3 x 3 cross or square

f is the image and g_0 the marker. Each step dilates and erodes g with the 3 x 3 element N, caps the dilation at f and takes the larger of the two. The steps repeat until nothing changes, at most 2000 times. Where the marker lies below the image this is reconstruction by dilation, and where it lies above, reconstruction by erosion. The tests check both cases against scikit-image.

Meyer defined levelings as images whose changes between neighbors always follow the original image. Where two neighbors differ in the result, they differ in the same direction and at least as much in the image. The leveling of an image with a marker is the limit of repeating (f min dilation of g) max erosion of g. Where the marker lies below the image this is reconstruction by dilation, and where it lies above, reconstruction by erosion.

Kernel or operator

There is no kernel. The Inspector lists the marker and the leveling step with the current sigma and connectivity.

Algorithm

  1. Blur the image with a Gaussian to get the marker.
  2. Repeat until nothing changes. Dilate and erode the marker, cap the dilation at the image, and take the larger value.

Parameters

Parameter Default Values Meaning
Marker blur sigma 2 0.5 to 10 px The marker is the image blurred by a Gaussian of this sigma, cut at 4 sigma.
Neighbors connectivity 8 neighbors 8 neighbors, 4 neighbors Which pixels count as joined when the reconstruction spreads.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope RGB RGB, Brightness only Which part of the color image the filter changes.

Implementation

leveling in web/src/core/filters/morphology/reconstruction.ts repeats the step with the 3 x 3 element until nothing changes, at most 2000 times. Large images can need many steps, so the preview runs only on demand. 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
Leveling, marker sigma 1 13.2 13.2 22.3 22.1 22.1 90 92.6 90 19.6 19.6

The marker is the row blurred with sigma 1. The leveling moves the row toward it. Wherever two neighbors end up different, the input differed in the same direction and by at least as much. So no new edges appear and no edge moves.

Complexity

  • Time: \(O(N s)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel and s the number of steps, which can grow with the image size. So the preview runs only on demand.

Artifacts and limitations

Limitations

  • Slow on large images, since the steps repeat until nothing changes.
  • The result depends on the marker.

Artifacts

  • Large flat zones with sharp borders, a cartoon look.

Tests

The reference repeats the same step with scipy.ndimage. Before the cases are written, the script checks that a marker below the image gives skimage.morphology.reconstruction by dilation and a marker above it gives reconstruction by erosion. The cases cover all five border modes for the marker.

References

  • Meyer, F. Levelings, image simplification filters for segmentation. Journal of Mathematical Imaging and Vision 20(1-2), 59 to 72, 2004. DOI 10.1023/B:JMIV.0000011319.21884.39.
  • 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.