imtophat

Syntax

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.

Examples

Use Top-hat Filtering to Correct Uneven Illumination

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.

Use Top-hat Filtering to Correct Uneven Illumination on the GPU

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.

More About

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.