我尝试使用图像处理工具箱来计算我的殖民地。我用imfindcircles
找到了殖民地和数量。但我遇到了一些问题:
(1)由于我的殖民地可能是白色和黑色,我试图在Bright
中使用ObjectPolarity
或黑暗来找到殖民地,并使用if循环来选择我最后的那个选择。但是我的if循环的第一步并没有真正起作用。
(2)使用imfindcircles
找到圆圈,我发现它适用于白色的殖民地,而这种方法对于黑人殖民地来说是一场灾难。我现在有点绝望,因为我无法找到其他方法来分割殖民地。
所以最后我需要:标记板中的每个菌落,计算菌落数,计算每个菌落大小,提取每个菌落的平均灰度值(颜色)。
非常感谢!!!
所以这是我的代码:
im = imread(test.jpeg)
imshow(im)
% to find the colony
[centersBright, radiiBright] = imfindcircles(im,[30 60],'ObjectPolarity','bright','Sensitivity',0.925,'Method','twostage','EdgeThreshold',0.1)
[centersDark, radiiDark] = imfindcircles(im,[30 60],'ObjectPolarity','dark','Sensitivity',0.925,'Method','twostage','EdgeThreshold',0.15)
% to select which one is the correct count. if one of the length(centres) value is lower than 10, I consider it as an error. But if both length(centres) is low than 10, I consider it as a treatment effect and accept the value.
if length(centersDark)<10<length(centersBright)
centers=centersBright
radii=radiiBright
elseif length(centersBright)<10<length(centersDark)
centers=centersDark
radii=radiiDark
else
centers=[centersBright,centersDark]
radii=[radiiBright,radiiDark]
end
% view and label the colony
h = viscircles(centers,radii)
for k = 1:length(radii)
string = sprintf('%d',k)
text(centers(k,1),centers(k,2),string,'color','y','HorizontalAlignment', 'center','VerticalAlignment', 'middle')
area(k)=pi*radii(k)^2
end
答案 0 :(得分:3)
建议的解决方案
虽然在输入的黑白版本中难以区分菌落及其周围环境,但使用阈值处理在色调空间中这样做并不困难。 原因是菌落具有与其背景不同的独特色调。 转换为HSV空格后,这将更加明显:
<强>代码强>
%reads the image
I = imread('colony2.png');
%convert to hsv
hsvIm = rgb2hsv(I);
%thresholding on the hue space
bwIm = hsvIm(:,:,1) < 0.15;
%find connected components
CC = bwconncomp(bwIm);
%choose only cc with sufficient amount of pixels
numPixels = cellfun(@numel,CC.PixelIdxList);
relevantCC = CC.PixelIdxList(numPixels > 10);
%generate a binary mask with these conencted componants
colonyMask = false(size(bwIm));
for ii=1:length(relevantCC)
colonyMask(relevantCC{ii}) = true;
end
%perform morpholopical operations for cleaning
colonyMask = imclose(colonyMask,strel('disk',1));
%display result
h = imshow(I); % Save the handle; we'll need it later
set(h, 'AlphaData', ~colonyMask);
<强>结果
选择阈值
通过选择色调分量直方图中的第一个选择
来选择阈值histogram(hsvIm(:,:,1))