Skip to content
Advertisement

Why does thresholding on image give a different result compared to when it is in an image with other things?

I have an image that when I apply a binary threshold on it, it gives a different result compared to when it is in an image with other things. I’m not sure if I’m setting the parameters for the thresholding function incorrectly as I took the example from the OpenCV documentation. Link to documentation: https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html

In my test program, I read in two images. One where the object is by itself and another where it is in an image with other objects. When I applied the threshold to the image1 I got the result I wanted. However, when I applied the threshold to image2 I partially got the result I wanted, but one of the blocks did not threshold correctly. Any ideas as to what may be causing this?

Image1 and its resultant threshold

Image2 and its resultant threshold

JavaScript

Advertisement

Answer

This is because of your usage of OTSU. It sets some sort of automatic threshold. Please refer to the following link

Advertisement