How can I use Otsuthresh correctly to convert an image to binary?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nathan Costin
il 19 Lug 2016
Commentato: Nathan Costin
il 19 Lug 2016
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 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 3-D Volumetric Image Processing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!