1

In the picture below there are some regions which are very bright (i.e. more white). Some bright regions are wide and some are narrow or thin. The red box covers one such wide bright spot, and blue box covers one thin bright spot. Thin bright spots are called edges and wide bright spots are called hot-spots.

I want to remove all the hot-spots from the image (i.e. make them black), but no edge should be removed.

My question is how to write Python code using OpenCV to remove all hot-spots but no edge?

enter image description here

S. M.
  • 157
  • 6

1 Answers1

2

Produce an Otsu binarized copy of the image, and call it image 2.

Perform erosion on it, and call that image 3. Now the hotspots remain, while the edges have disappeared. A simple check at this point would use this result to mask the original image 1.

To produce a final image choose a threshold distance K, and iterate over image 1's pixels, copying as you go. Clear the pixel to black if it is present in image 2 and you can find one that is still illuminated within K pixels of it on image 3.


An alternate approach would be to use the several connected components in the eroded image 3 to perform flood fill in the original image. The tricky aspect here is dealing with adaptive thresholding. Probably better to let Otsu worry about choosing the locally appropriate values for loDiff and upDiff.

J_H
  • 2,739
  • 11
  • 19
  • I need more explanation. – S. M. Jun 01 '23 at 21:33
  • 2
    Either produce a circular mask of radius K, or use a square region with side 2 × K. Move that kernel over the image1 source pixels, computing `1` if it reveals any illuminated pixel in image3 and `0` otherwise. Multiply the image1 pixel by the computed value when generating each output pixel. – J_H Jun 01 '23 at 21:44
  • Please see [this answer](https://datascience.stackexchange.com/questions/121793/how-to-remove-the-hotspots-from-given-image-by-using-python-and-opencv) , I have implemented your algorithm. – S. M. Jun 04 '23 at 11:16