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]

7 次查看(过去 30 天)
please help me with the simples code possible.

回答(1 个)

Image Analyst
Image Analyst 2022-9-22
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 个评论
Image Analyst
Image Analyst 2022-9-22
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

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by