필터 지우기
필터 지우기

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

조회 수: 5 (최근 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개)

Community Treasure Hunt

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

Start Hunting!

Translated by