O'Reilly logo

Learn OpenCV 4 by Building Projects - Second Edition by Prateek Joshi, Vinicius G. Mendonca, David Millan Escriva

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required