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.
0 个评论
回答(1 个)
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])
threshold = graythresh(grayImage) % Find threshold using Otsu method.
% If it's uint 8 you want to multiply by 255
threshold = 255 * graythresh(grayImage)
2 个评论
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)
mask = grayImage > threshold;
meanGrayLevel = mean(grayImage(mask))
varGrayLevel = var(double(grayImage(mask)))
stDevGrayLevel = std(double(grayImage(mask)))
minGrayLevel = min(grayImage(mask))
maxGrayLevel = max(grayImage(mask))
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!