Qu

imtophat

Builtin index · Images

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

Input: img, radius · Output: result

What it is

img is a binary/grayscale Image; radius is a positive integer. The image minus its opening: what the opening removed. The standard way to pull small bright features off an uneven background.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = imtophat(img, radius) <br> imtophat(img, se=)
img Imageimg is a binary/grayscale Image.
radius —radius is a positive integer.
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

imtophat(img, radius) (original minus opening — extracts small bright features / corrects a slowly-varying bright background; the primary foreground/background separation mechanism beyond a plain threshold) / imbothat(img, radius) (closing minus original — the dark-feature dual). 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.