The four classical mathematical-morphology operations — Erosion, Dilation, Opening, Closing — with an elliptical structuring element, live preview, and mask integration. Core workhorses for mask editing (grow or shrink a star mask, close small holes in a selection, open away speckle), small-feature removal, and binary-image clean-up. OpenCV engine underneath; everything else is the dialog, live preview, and document mask integration.
Runs on the active document's image. Non-modal and stays open after Apply so you can keep tweaking or hop to another image. Opens with a live preview at the default settings (Erosion, kernel 3, one iteration).
Shrinks bright features by setting each pixel to the minimum value within its kernel neighbourhood. Thin bright structures (single-pixel noise, hot pixels, isolated hair-thin features) disappear completely when they're smaller than the kernel.
The dual of erosion: each pixel takes the maximum within the kernel neighbourhood, growing bright features outward. Dark gaps smaller than the kernel get filled in.
Erosion followed by dilation. The sequence removes bright features smaller than the kernel without shrinking the larger features that survive the erosion step.
Dilation followed by erosion. The dual of opening: fills dark holes smaller than the kernel without growing the already-bright features outward.
Dropdown with the four choices above. Reset returns to Erosion.
SpinBox, 1–31, odd only (stepping by 2). The diameter of the elliptical structuring element in pixels. Even numbers are auto-rounded up to the next odd value because morphology needs a centre pixel to be well-defined. Larger kernels affect larger features but also take proportionally longer to compute.
SpinBox, 1–10. Number of times the operation is applied in sequence. For Erosion and Dilation this is equivalent to using a larger structuring element but runs faster for low iteration counts (two iterations of a 3×3 erode cover approximately the same reach as a single 5×5 erode). For Opening and Closing each iteration is a full open/close pair, which has a slightly different effect from using a bigger kernel — the intermediate dilate/erode steps happen at the smaller scale.
The main area shows a live preview that updates with a 200 ms debounce after any parameter change. Zoom In / Zoom Out / Fit to Preview buttons sit above the Apply row, and the view supports cursor-anchored wheel zoom with the standard SASpro behaviour. If the active document carries a mask, the result is blended through it so only masked regions receive the operation — both in the live preview and the final Apply.
Apply runs the final full-resolution computation and commits as an undoable edit named “Morphology”. All three slider values are recorded in the preset so Replay Last Action reproduces the exact run. The dialog stays open so you can switch to another document and apply with the same settings.
Reset returns to Erosion / kernel 3 / 1 iteration; Cancel discards. The grip at the bottom-left carries the current operation + kernel + iterations and can be dragged onto the canvas to make a shortcut tile, or dropped directly on an image to apply those settings headlessly. Double-clicking a shortcut reopens this dialog pre-seeded with the saved values.
All processing on float32 in [0, 1] with intermediate uint8 for OpenCV's morphology functions. Mono inputs operate on the single channel; RGB inputs are processed per-channel independently (OpenCV handles this natively).
Morphology operates on grey-level images via the min/max over a
structuring-element neighbourhood K. Erosion takes the
pixelwise minimum over that neighbourhood:
Dilation takes the maximum:
Opening and Closing compose erosion and dilation in the two orderings:
Opening removes bright features smaller than the kernel because the initial erosion kills them completely and the following dilation can only grow back what's still there. Closing fills dark holes smaller than the kernel symmetrically — the initial dilation spans them, the following erosion restores the outer edges but leaves the newly-filled interior intact.
The two primitives are duals under image complement: eroding an image is equivalent to dilating its negative (with a reflected kernel) and complementing back.
The elliptical kernel used here is point-symmetric so
K = K̂, and the duality reduces to
“eroding bright is the same as dilating dark”. This is
why Erosion grows the dark regions of your image as a side effect
of shrinking the bright ones, and vice versa.
SASpro uses OpenCV's MORPH_ELLIPSE structuring
element throughout — a filled disc inscribed in a
k×k bounding box with radius:
Discs are the natural choice because they are isotropic — the operation has no preferred direction, so a round star stays round after erosion rather than becoming square or diamond-shaped the way it would with a rectangular kernel. OpenCV approximates the disc on the integer pixel grid, which is why the smallest meaningful kernel is 3 px (a 1×1 kernel is an identity).
The Iterations parameter applies the chosen operation
n times in succession:
For Erosion and Dilation this is equivalent to a single
operation with a larger structuring element — specifically,
n iterations of a kernel with radius r
cover approximately the same reach as a single kernel with radius
nr. The multi-iteration form is faster when
r is small and n is small, slower when
n is large (because OpenCV's single-kernel morphology
scales better than linearly). For Opening and Closing, each
iteration is a full erode-dilate (or dilate-erode) pair, so the
behaviour differs subtly from using a larger kernel: the
intermediate step happens at the smaller scale, which can affect
how features interact.
Mono inputs ((H, W) or (H, W, 1)) are flattened to a 2-D array and processed directly, then reshaped back to the original ndim on output. RGB inputs are handed to OpenCV's morphology functions as a single multi-channel array; OpenCV applies the operation independently to each channel using the same kernel. Because morphology is a nonlinear order-statistic operation, per-channel processing can produce slight colour shifts in features with narrow colour-channel differences — expected behaviour, not a bug; convert to luminance first if you want strictly colour-invariant morphology.
If the active document carries a mask
m ∈ [0, 1], the morphology result
is blended with the untouched source through the mask:
applied after the full-image morphology computation. Both the live preview and the final Apply respect this mask identically. The mask is resampled to the processed image's dimensions if needed. Note that this gates where the morphology applies; the morphology itself still operates on the whole image, so a feature near a mask boundary can be affected by pixels across the boundary during the erode/dilate step before the blend restores the outside to its original state.
cv2.erode,
cv2.dilate, and cv2.morphologyEx, which
use efficient van Herk-Gil-Werman separable kernels for rectangular
and ellipse-approximate shapes. SASpro's additions are the
mono/RGB dispatcher, the live-preview pipeline with its 200 ms
debouncing, the document-mask integration, and the preset
editor and grip system.