H. Chamsaddin
H. Chamsaddin

Reputation: 95

How to threshold an image 32 bit using Otsu’s Binarization?

I tried all the possibilities using the following instruction:

ret,thresh = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

But it always gives me the same error:

error: (-215) src.type() == CV_8UC1 in function cv::threshold

There is a possibility to threshold an image 32-bit, single channel ??! Thanks in advance

Upvotes: 1

Views: 5076

Answers (1)

Miki
Miki

Reputation: 41765

According to OpenCV doc for cv::threshold:

Currently, the Otsu’s method is implemented only for 8-bit (CV_8UC1) images.

For other methods, according to the documentation, are valid single-channel matrices, 8-bit (CV_8UC1) or 32-bit floating point (CV_32FC1).

However, it should work also for 16-bit (CV_16SC1) matrices

For cv::adaptiveThreshold, type must be CV_8UC1.

Upvotes: 2

Related Questions