Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV get only Otsu Threshold value like Matlab function graythresh

How to get only Otsu Threshold value using OpenCV like Matlab function graythresh.

For example, if I write this code I get binary image like using Matlab function im2bw:

Mat bw;
uint8_t data[14] = { 10, 10, 10, 10, 10, 10, 20, 20, 54, 54, 54, 54, 55, 55 };
Mat M(1, 14, CV_8UC1, &data);
threshold(M, bw, 0, 1, CV_THRESH_BINARY | CV_THRESH_OTSU);
like image 734
pulsen Avatar asked Mar 07 '26 15:03

pulsen


1 Answers

The function cv::threshold() returns the computed threshold value if you set THRESH_OTSU flag.

double thres_val = cv::threshold(M, bw, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);

See cv::threshold() for more information.

like image 106
Kornel Avatar answered Mar 10 '26 09:03

Kornel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!