You are here : matlabImage Processingimtophat

imtophat() - Image Processing

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.


Syntax

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


Example

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. 
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)
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.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)


Output / Return Value


Limitations


Alternatives / See Also


Reference