imclose
result =imclose(img, radius)<br>imclose(img, se=)
Input: img, radius · Output: result
What it is
img is a binary Image; radius is a positive integer (same square structuring-element convention as imdilate). Morphological closing (dilate then erode) — fills small background holes without enlarging the overall shape.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = imclose(img, radius) <br> imclose(img, se=) | img Imageimg is a binary Image.radius —radius is a positive integer (same square structuring-element convention as imdilate). | result Image | Returns a new Image, same dimensions. (imopen/imerode, erosion and opening, also exist alongside it in the same match arm pair but aren't in this chapter's requested scope — see the "More functions" table below.) Same additive se= kwarg as imdilate 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
imopen(img, radius) (erode then dilate — removes small foreground specks) / imclose(img, radius) (dilate then erode — fills small background holes). Same additive se= kwarg as imerode/imdilate above.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.