警告 - 在此完成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} }})
这是一张示例图片:
答案 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
结果: