# 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)
Commented: Image Analyst on 22 Sep 2022

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 CommentsShowHide 1 older comment
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
meanGrayLevel = 7.9000
varGrayLevel = 1.4333
stDevGrayLevel = 1.1972
minGrayLevel = uint8 6
maxGrayLevel = uint8 9

### Categories

Find more on Image Thresholding in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by