How can I use Otsuthresh correctly to convert an image to binary?

3 ビュー (過去 30 日間)
Nathan Costin
Nathan Costin 2016 年 7 月 19 日
コメント済み: Nathan Costin 2016 年 7 月 19 日
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)

採用された回答

Thorsten
Thorsten 2016 年 7 月 19 日
編集済み: Thorsten 2016 年 7 月 19 日
I your aim is to separate the bacteria from the background, I think you cannot do this with a simple thresholding, because the interior of the bacteria have about the same gray level as the background.
  2 件のコメント
Nathan Costin
Nathan Costin 2016 年 7 月 19 日
That is what I'm aiming to do however, I need to be able to count the bacteria and plot their centers later on (I have already written this code) so resulting image needs to be separate with no parts touching, I've used strel elements to do this in the past but I would like to automate the process
Nathan Costin
Nathan Costin 2016 年 7 月 19 日
I'm trying to calculate the values of lower and upper correectly

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by