Unexpected result of a threshold operation
I read a white picture using OpenCV:
I apply this threshold over it:
import cv2
# Read image
src = cv2.imread("threshold.png", cv2.CV_LOAD_IMAGE_GRAYSCALE)
# Set threshold and maxValue
thresh = 0
maxValue = 255
# Basic threshold example
th, dst = cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY);
# Find Contours
contours, hierarchy=cv2.findContours(dst,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
# Draw Contour
cv2.drawContours(dst,countours,-1,(255,255,255),3)
cv2.imshow("Contour",dst)
So according the cv2.THRESH_BINRARY
thresholding type, I logically expect a totally white picture. Why ? because I set thresh=0
and maxValue=255
, so the result I expect is logic according to the official documentation that says in this case:
But I get a totally black picture as a result (pixels of dst
set to 0
even if they are greater than thresh
in src
picture)
Why this ? What am I misunderstanding ?
Thank you for any hints. Begueradj
where do you get a black picture? in imshow() ? findContours "eats" up the image.
try another imshow directly after the threshold.
@berak you are right !!! it is white as i expected after removing what you asked me ! But why the contours are drawn in white and everything else is black when I set thresh = 250 ?
please add some more info about the new problem in a second part of the question.