imerode
result =imerode(img, radius)<br>imerode(img, se=)
Input: img, radius · Output: result
What it is
img is a binary Image; radius is a positive integer, the half-width of a square structuring element of side 2*radius+1. Binary morphological erosion — shrinks foreground regions and removes specks smaller than the element.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = imerode(img, radius) <br> imerode(img, se=) | img Imageimg is a binary Image.radius —radius is a positive integer, the half-width of a square structuring element of side 2*radius+1. | imdilate —see "Structuring elements" above | Returns a new Image, same dimensions as img. Same additive se= kwarg as imdilate (see "Structuring elements" above), added in v0.4.0. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
m = [0, 0, 0, 0, 0, 0; 0, 255, 255, 0, 255, 0; 0, 255, 255, 0, 0, 0; 0, 0, 0, 0, 0, 0; 0, 255, 0, 0, 255, 255; 0, 0, 0, 0, 255, 255]
img = image_from_matrix(m)
imshow(img)
eroded = imerode(img, 1)
dilated = imdilate(img, 1)
opened = imopen(img, 1) # drops the lone speck
closed = imclose(img, 1) # fills small gaps
bright = imtophat(img, 1) # small bright features
dark = imbothat(img, 1) # small dark features
imshow(opened)
print(eroded.width, dilated.width, opened.width, closed.width, bright.width, dark.width)
6 6 6 6 6 6
from images
How it works
and foreground/background separation (§ blob-manipulation pass, 2026-08-24). See image::Image's own "Binary morphology..." doc-comment section for the full binary-mask convention this whole group shares: a Value::Image is treated as "binary" when every pixel is grayscale (R=G=B) with two intended levels, 0 = background / 255 = foreground (is_foreground actually reads >=128, so a slightly antialiased mask still behaves sanely). No threshold/ otsu_threshold builtin existed in this shared working tree when this landed (a sibling agent's own lane) — this is a documented, independent design choice, not a guess at matching code that hadn't landed yet; reconcile if the sibling's own producer ends up using a different convention. imerode(img, radius) / imdilate(img, radius) — a square structuring element of side 2*radius+1 (documented choice over a disk — see image::Image::erode's doc comment). Additive se= kwarg (§ SE/hit-miss/watershed pass, 2026-09-25): an explicit structuring-element mask Image (disk()/line(), or hand-built) in place of the radius-implied square — radius is simply not read at all when se= is given, so the old two-positional-argument form keeps working unchanged.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.