Detect black object on image with lighting effect

209 Views Asked by At

I am trying to detect an blakc box on an image with different lighting effects. What I did until now, was to transform my image in HSV colorspace then make a filter range to get the black color, then finding the best polygon contours around that. This works for most of my cases but I came to that image where it does not work and I understand why, but I cannot find a way to make it work. Let me explain, here is the image:

enter image description here

This is the mask I get:

enter image description here

And as you can see on the following image, the red square is not detected when the green square is detected. However by nayed eye it is obvious that the red square is black (grey) and the green square is white. What can I do to do that?

enter image description here

Thanks in advance for any help

1

There are 1 best solutions below

2
mimocha On

Well, the reason it doesn't work is because your color threshold doesn't cover this specific case. To the computer, the pixel values inside the red box is beyond the accepted threshold, and the pixel values inside the green box is within the accepted threshold; regardless of what you, as a human, say you see.

One way you could try to fix this, is by finetuning your threshold further to include the pixels in the red box, and exclude those in the green box.

However, in the very likely scenario that you cannot find any color threshold value that can correctly distinguish your black box from the background image - you have reached the limits of what simple color thresholding can achieve for you.

At which point you will have to experiment with combining other methods for detecting and locating your black box. From post-processing your thresholded values with Morphological Operation and edge detection and noise removal with filters, to other more advanced techniques for image segmentation.