OpenCV Each pixel in the return image from adaptiveThreshold function is value 255

486 Views Asked by At

I apply adaptive thresholding to gray scale image, and I would like to apply normal thresholding to the return image of that function. This doesn't work since somehow every pixel in the return image is set to 255. I don't understand why this is since imshow displays the return image from adaptive threshold as you would expect it to, and it responds to changes in parameters. So why is every pixel 255 and why am I unable to get results putting that image into the normal threshold function?

Im using opencv 4.0.0.

image = cv2.imread('../photos/neptune.jpg', 0)
th2 = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 3, 2)

# doesnt matter what second parameter is.
_, thresh = cv2.threshold(th2, 200, 255, cv2.THRESH_BINARY)
1

There are 1 best solutions below

1
Dmitri S On

cv2.adaptiveThreshold function produces as output a black and white image. A black and white image is already binary and running it through a binary filter is redundant, but when you do it anyway, you can get one of the following: the same, fully black, or fully white image.