python cv2 convert image to binary 1

python cv2 convert image to binary

(thresh, im_bw) = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

Here is what the above code is Doing:
1. We first convert the image to grayscale.
2. Then we apply the cv2.threshold() function to the image.
3. The first argument is the image we want to threshold.
4. The second argument is the threshold value which is used to classify the pixel values.
5. The third argument is the maxVal which represents the value to be given if pixel value is more than (sometimes less than) the threshold value.
6. The fourth argument is the type of threshold.

Similar Posts