MATLAB:将来自imfindcircles的数据与来自bwconncomp的数据进行比较

时间:2014-11-13 20:32:38

标签: matlab image-processing

警告 - 在此完成n00b。

我正在开展一个需要找到漏洞的项目。我找到了一种相当准确的方法(bwconncomp),但我得到了一些我不需要的额外数据(也就是没有洞的洞)。现在这些洞是圆形的,所以我打算用imfindcircles进行检查。

所以我需要做的是从imfindcircles获取中心坐标和半径信息来过滤掉bwconncomp中的非圆形孔。我该如何解决这个问题?

%Find Circles
[centersDark, radiiDark] = imfindcircles(im,[10 75],'ObjectPolarity','dark');

%Find holes (I think)
cc = bwconncomp(BW);

%Put box around holes (prints to figure for debugging... kinda)
rp = regionprops(cc,'BoundingBox');

所以,为了澄清,我需要弄清楚如何从cc收到的数据中清除imfindcircles中的额外信息(这些变量为centersDark和{{1} }})

这是一张示例图片:Here's a sample image:

1 个答案:

答案 0 :(得分:0)

您还可以改善细分阶段:

close all;
% read input
im = imread('holes.bmp');
grayImg = rgb2gray(im);

% create an image where holes are removed
med = medfilt2(grayImg,[100,100],'symmetric');

figure();
imshow(med);
title('median');

% subtract image with holes from image without holes
% so the whole process is less dependent on ilumination of foreground
diff = double(med) - double(BW);

figure();
imshow(uint8(diff+127));
title('difference');

% apply threshold
bw = diff > 50;

figure();
imshow(bw);
title('threshold');

% remove small objects
SE = strel('disk',10);
opened = imopen(bw,SE);

figure();
imshow(opened);
title('imopen');

% get bounding boxes for each hole
cc = bwconncomp(opened);
rp = regionprops(cc,'BoundingBox');

% draw rectangles
figure();
imshow(im);
hold on;
title('result');
for i = 1:length(rp)
    rectangle('Position',rp(i).BoundingBox,'EdgeColor','red')
end

结果:

enter image description here