1

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)
Peyton Hanel
  • 374
  • 1
  • 3
  • 13
  • Would you be able to upload your neptune.jpg to imgur so we can replicate the code? – PeptideWitch Jan 25 '20 at 01:38
  • 1
    "Each pixel in the return image from adaptiveThreshold function is value 255", yes that's what a threshold is supposed to do. It makes the image a binary image (grayscale) from `[0...255]`. Try `thresh = cv2.threshold(th2, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]` – nathancy Jan 25 '20 at 03:08

1 Answers1

4

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.

Dmitri S
  • 151
  • 5