How can I use Otsuthresh correctly to convert an image to binary?
3 次查看(过去 30 天)
显示 更早的评论
I have been trying to convert an image to binary by separating out the image into RGB, plotting a histogram for each colour then using Ostuthresh to get a value to use in im2bw. My threshold limits have always been wrong and I'm not sure why. When I plot the histogram and use BinLimits I get a lower value of 118 and upper of 205. I know that the limit needs to be near 0.7 however I cannot seem to achieve this. Although I am practicing this on one image the aim to to make it general.
bac_1 = imread('multibac.png');
r1 = bac_1(:,:,1);
g1 = bac_1(:,:,2);
b1 = bac_1(:,:,3);
red_testogram = histogram(r1);
if red_testogram.BinWidth ==1 %this loop decides how to adjust the number of Bins to make BinWidth equal to 1
new_red_binnumber = red_testogram.Numbins;
else
new_red_binnumber = (red_testogram.NumBins * red_testogram.BinWidth); %chooses the bin width
end
r_imogram = histogram(r1, new_red_binnumber)
avg = mean(r1(:));
stdev = std(double(r1(:)));
lower = r_imogram.BinLimits(1);
upper = r_imogram.BinLimits(2);
t = otsuthresh(histcounts(r1,lower:upper));
bwr = im2bw(r1,t);
imshow(bwr)
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!