Unexpected result of a threshold operation

asked 2015-02-27 04:45:49 -0600

begueradj gravatar image

updated 2015-02-27 04:46:15 -0600

I read a white picture using OpenCV:

enter image description here

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:

enter image description here

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

edit retag flag offensive close merge delete

Comments

2

where do you get a black picture? in imshow() ? findContours "eats" up the image.

try another imshow directly after the threshold.

berak gravatar imageberak ( 2015-02-27 04:51:26 -0600 )edit

@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 ?

begueradj gravatar imagebegueradj ( 2015-02-27 04:57:02 -0600 )edit

please add some more info about the new problem in a second part of the question.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-02-27 06:24:28 -0600 )edit