how to calculate otsu threshold value for the matrix given [1 3 4 5 3 2; 4 6 2 4 1 9; 0 4 9 5 8 3; 2 4 9 4 2 1; 0 1 9 3 4 8; 5 6 4 7 3 8]

4 views (last 30 days)
please help me with the simples code possible.

Answers (1)

Image Analyst
Image Analyst on 22 Sep 2022
grayImage = uint8([1 3 4 5 3 2; 4 6 2 4 1 9; 0 4 9 5 8 3; 2 4 9 4 2 1; 0 1 9 3 4 8; 5 6 4 7 3 8])
grayImage = 6×6
1 3 4 5 3 2 4 6 2 4 1 9 0 4 9 5 8 3 2 4 9 4 2 1 0 1 9 3 4 8 5 6 4 7 3 8
threshold = graythresh(grayImage) % Find threshold using Otsu method.
threshold = 0.0196
% If it's uint 8 you want to multiply by 255
threshold = 255 * graythresh(grayImage)
threshold = 5
  2 Comments
Image Analyst
Image Analyst on 22 Sep 2022
Not sure what that means. An element of the image is a single number and the mean is the value of the pixel, the variance is zero, and the max and min are again the value of the pixel.
If you want it of just the part above the threshold you'd do
grayImage = uint8([1 3 4 5 3 2; 4 6 2 4 1 9; 0 4 9 5 8 3; 2 4 9 4 2 1; 0 1 9 3 4 8; 5 6 4 7 3 8]);
threshold = graythresh(grayImage); % Find threshold using Otsu method.
% If it's uint 8 you want to multiply by 255
threshold = 255 * graythresh(grayImage)
threshold = 5
mask = grayImage > threshold;
meanGrayLevel = mean(grayImage(mask))
meanGrayLevel = 7.9000
varGrayLevel = var(double(grayImage(mask)))
varGrayLevel = 1.4333
stDevGrayLevel = std(double(grayImage(mask)))
stDevGrayLevel = 1.1972
minGrayLevel = min(grayImage(mask))
minGrayLevel = uint8 6
maxGrayLevel = max(grayImage(mask))
maxGrayLevel = uint8 9

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by