Top Hat transform

This transform extracts finer details from the images. This is the difference between the input image and its morphological opening. This gives us the objects in the image that are smaller than the structuring element and brighter than the surroundings. Depending on the size of the structuring element, we can extract various objects in the given image:

If you look at the output image carefully, you can see those black rectangles. It means that the structuring element was able to fit in there, and so those regions are blackened out. Here is the function:

Mat performTopHat(Mat inputImage, int morphologyElement, int morphologySize) ...

Get Learn OpenCV 4 by Building Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.