Qu

imopen

Builtin index · Images

result = imopen(img, radius) <br> imopen(img, se=)

Input: img, radius · Output: result

What it is

img is a binary Image; radius is a positive integer (same structuring-element convention as imerode). Morphological opening (erode then dilate) — removes specks smaller than the structuring element while leaving larger shapes their size.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = imopen(img, radius) <br> imopen(img, se=)
img Imageimg is a binary Image.
radius —radius is a positive integer (same structuring-element convention as imerode).
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)
output
6 6 6 6 6 6
a synthetic field with one bright patch

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.