Main Content

imtophat

Top-hat filtering

Description

example

J = imtophat(I,SE) performs morphological top-hat filtering on the grayscale or binary image I, returning the filtered image, J. Top-hat filtering computes the morphological opening of the image (using imopen) and then subtracts the result from the original image. SE is a single structuring element object returned by the strel or offsetstrel functions.

J = imtophat(I,nhood) top-hat filters the image I, where nhood is a matrix of 0s and 1s that specifies the structuring element neighborhood. The imtophat function determines the center element of the neighborhood by floor((size(nhood)+1)/2).

This syntax is equivalent to imtophat(I,strel(nhood)).

Examples

collapse all

This example shows how to use top-hat filtering with a disk-shaped structuring element to remove uneven background illumination from an image with a dark background.

Read an image and display it.

original = imread('rice.png');
imshow(original)

Create the structuring element.

se = strel('disk',12);

Perform the top-hat filtering and display the image.

tophatFiltered = imtophat(original,se);
figure
imshow(tophatFiltered)

Use imadjust to improve the visibility of the result.

contrastAdjusted = imadjust(tophatFiltered);
figure
imshow(contrastAdjusted)

Input Arguments

collapse all

Input image, specified as a grayscale image or binary image of any dimension.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Structuring element, specified as a single strel object or offsetstrel object. If the image I is data type logical, the structuring element must be flat.

Structuring element neighborhood, specified as a matrix of 0s and 1s.

Example: [0 1 0; 1 1 1; 0 1 0]

Output Arguments

collapse all

Top-hat filtered image, returned as a grayscale image or binary image. J has the same class as input image I.

Extended Capabilities

See Also

Functions

Objects

Introduced before R2006a