How to get the threshold value from Otsu's method?

8 views (last 30 days)
On MathWorks webpage for the function imbinarize it says:
"Use graythresh or otsuthresh to compute a global image threshold."
According to their documentation, they both calculate the threshold value by using Otsu's method.
I tried this with the coins.png image:
using otsuthresh function:
img = imread('coins.png');
[counts,x] = imhist(img,16);
stem(x,counts);
T = otsuthresh(counts);
BW = imbinarize(imgNorm,T);
subplot(1,2,1)
imshow(img); title('original image');
subplot(1,2,2)
imshow(BW); title('binary image');
T = 0.467
using graythresh function:
img = imread('coins.png');
T = graythresh(img);
BW = imbinarize(img,T);
subplot(1,2,1)
imshow(img); title('original image');
subplot(1,2,2)
imshow(BW); title('binary image');
T = 0.494
I have two questions:
  1. What is the difference between these two thresholds? and which one refers to global thresholding method?
  2. How can I get the gray-level value at the threshold? (where is the threshold at the horizontal axis in the histogram?)

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!