Top-hat transform

There exist two types of top-hat transform: the white top-hat transform is defined as the difference between the input image and its opening by some structuring element, while the black top-hat transform is defined dually as the difference between the closing and the input image.

be a grayscale image, mapping points from a Euclidean space or discrete grid E (such as

Both top-hat transforms are images that contain only non-negative values at all pixels.

Assume that the user is only interested in small blobs on the image and wants to remove the larger bright objects.

However, selecting different shapes and sizes for the structuring element result in different images depending on whether objects fit in the structuring element or not.

The other example is an image under nonuniform illumination, where the user wants to extract objects separately from background.

However, if the image is under nonuniform lighting, it is possible that segmentation errors might present themselves since some objects in darker area have close intensity values as background intensity values and would not be extracted by only utilizing threshold method.

In this case, before Otsu's method is applied to input image, white top-hat transform should be implemented to correct nonuniform lighting condition and make obvious contrast between background and objects.

for original image and applied white top-hat transform respectively.