top hat and black hat

  1. Top hat

   The difference between the original image and the result image of "open operation" is calculated as follows:

Dst=tophat(src,element)=src-open(src,element)

   Because the result of the opening operation is to enlarge the crack or the local low-brightness area, therefore, subtracting the image after the opening operation from the original image, the resulting image highlights the brighter area than the area around the outline of the original image. And this operation is related to the size of the selected kernel.

The top-hat operation is used to separate patches that are lighter than their neighbors. When an image has a large background, and the small items are relatively regular, you can use the top hat operation for background extraction.

     2. Black hat calculation

     The difference between the original image and the result image of "open operation" is calculated as follows:

Dst=blackhat(src,element)=close(src,element)-src

The effect map after the black hat operation highlights the darker area than the area around the outline of the original image, and this operation is related to the size of the selected kernel.

Black hat operation is used to separate patches that are darker than neighboring points.

      3.API:

Cv.morphologyEx(img,op,kernel)

parameter:

Img: the image to process

Op: processing method

 

Kernel: nuclear structure

Example:

 

Guess you like

Origin blog.csdn.net/m0_62064241/article/details/126695159