当我不能使用黑白图像时如何分割菌落

how to segment the colony When I can't use bw image

我尝试使用图像处理工具箱来计算我的群体。我使用 imfindcircles 找到菌落并计数。但是我遇到了一些问题:

(1)由于我的殖民地可能是白色和黑色的,我尝试在ObjectPolarity中使用Bright或Dark来找到殖民地,并使用if循环到select 我最终选择了哪一个。但是我的 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

建议的解决方案

虽然在输入的黑白版本中很难区分菌落及其周围环境,但在色调 space 中通过使用阈值处理并不难。 原因是菌落具有不同于其背景的独特色调。 转换为 HSV space:

后会更加明显

因此,我建议采用以下解决方案:

  1. 将输入图像转换为 HSV space
  2. 对色调分量使用阈值。
  3. 提取连通分量
  4. 使用足够大的连通分量作为掩码
  5. 执行 imclose 操作以清理工件

代码

%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);

结果

阈值选择

通过选择色调分量直方图中的第一个 pick 来选择阈值

histogram(hsvIm(:,:,1))