Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imtophat

Top-hat filtering

Syntax

IM2 = imtophat(IM,SE)
IM2 = imtophat(IM,NHOOD)
gpuarrayIM2 = imtophat(gpuarrayIM,___)

Description

IM2 = imtophat(IM,SE) performs morphological top-hat filtering on the grayscale or binary input image IM. Top-hat filtering computes the morphological opening of the image (using imopen) and then subtracts the result from the original image. imtophat uses the structuring element SE, where SE is returned by strel. SE must be a single structuring element object, not an array containing multiple structuring element objects.

IM2 = imtophat(IM,NHOOD) where NHOOD is an array of 0s and 1s that specifies the size and shape of the structuring element, is the same as imptophat(IM,strel(NHOOD)).

gpuarrayIM2 = imtophat(gpuarrayIM,___) performs the operation on a GPU. NHOOD is the structuring element specified by strel(NHOOD), if NHOOD is an array of 0s and 1s that specifies the structuring element neighborhood. If NHOOD is a gpuArray, strel(gather(NHOOD)) specifies the structuring element neighborhood.

Code Generation support: Yes.

MATLAB Function Block support: Yes.

Class Support

IM can be numeric or logical and must be nonsparse. The output image IM2 has the same class as the input image. If the input is binary (logical), the structuring element must be flat.

gpuarrayIM must be a gpuArray of type uint8 or logical. When used with a gpuArray, the structuring element must be flat and two-dimensional.

The output has the same class as the input.

Examples

collapse all

You can use top-hat filtering to correct uneven illumination when the background is dark. This example uses top-hat filtering with a disk-shaped structuring element to remove the uneven background illumination from an image.

Read an image and display it.

original = imread('rice.png');
figure, 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)

You can use top-hat filtering to correct uneven illumination when the background is dark. This example uses top-hat filtering with a disk-shaped structuring element to remove the uneven background illumination from an image.

Read an image and display it.

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

Create the structuring element.

se = strel('disk',12);

Perform the top-hat filtering and display the image. Note how the example passes the image to the gpuArray function before passing it to the imtophat function.

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

Use imadjust to improve the visibility of the result. The gather function is used to retrieve the contents of the gpuArray from the GPU.

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

More About

collapse all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. Note that if you choose the generic MATLAB Host Computer target platform, the function generates code that uses a precompiled, platform-specific shared library. Use of a shared library preserves performance optimizations but limits the target platforms for which code can be generated. For more information, see Understanding Code Generation with Image Processing Toolbox.

When generating code, the image input argument, IM, must be 2-D or 3-D and the structuring element input argument, SE, must be a compile-time constant.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.

Introduced before R2006a

Was this topic helpful?