如何删除此图像中的轮廓圆?

时间:2014-10-09 09:12:35

标签: matlab image-processing outline

你们可以就如何删除此图像中的圆形轮廓提出可行的方法吗? Imfindcircles对我不起作用。你能建议其他方法吗? http://i.stack.imgur.com/RuD7v.jpg

enter image description here

2 个答案:

答案 0 :(得分:2)

假设BW是包含轮廓并且要删除的二进制图像,您可以使用基于regionprops的方法 -

perimtrs = regionprops(BW, 'Perimeter'); %// perimeters for each connected component 
px = regionprops(BW, 'PixelIdxList'); %// pixel list for each connected component 
[~,idx] = max(struct2array(perimtrs)); %// get the component with max perimeter 
                                       %// that represents the outline circle
BW(px(idx).PixelIdxList) = 0;   %// Set all pixels of the outline circle to zero, 
                                %// that is they are removed

如果您希望保持最安全的功能,可以使用BoundingBox中的regionprops属性,而不是'Perimeter',如下所示 -

%// Get the bounding box properties for each connected component
perimtrs = regionprops(BW, 'BoundingBox'); 

%// Get bounding box area for each component and get the ID for the largest
%// box that corresponds to the outline circle
bound_box = reshape(struct2array(perimtrs),4,[]);
bound_box_area = bound_box(3,:).*bound_box(4,:);
[~,idx] = max(bound_box_area);

%// Set the pixels corresponding to the outline circle to zeros
px = regionprops(BW, 'PixelIdxList');
BW(px(idx).PixelIdxList) = 0; 

或者,你可以避免第二次使用regionprops通过调用regionprops来获取像素列表,这可能对性能有效,但我还没有测试过,所以可以'保证。新方法看起来像这样 -

perimtrs = regionprops(BW, 'Perimeter');
[~,idx] = max(struct2array(perimtrs))
[L,num] = bwlabel( BW ); %// Label connected components
BW(L==idx)=0; %// Select all pixels corresponding to label idx and set those to zero 

同样,您可以将此bwlabel方法与BoundingBox的{​​{1}}混合使用。

答案 1 :(得分:1)

好的,所以这里提出一个假设,即不将界面视为圆形,既不是单个区域,也不是具有最大周长。

%Assume A as your original image (left image), and bin_A as your binary image (right image)
thres=graythresh(A)
mask_A=im2bw(A,thres);
mask_A=imerode(mask_A,ones(3));
bin_A=bin_A.*mask_A;