2016-06-14 40 views
0

我有与bwconncomps分离连接的组件的二进制图像(附加)。我试图找出每个组件的轮廓,但在某种程度上,我仍然可以返回到填充对象 - (我使用的大纲作为掩模灰度图像上提取一些值,然后根据所值感兴趣的充满原始的区域)MATLAB:在二值图像的感兴趣区域的隔离周长:bwmorph发出

进行操作。当我运行附加的图像bwconncomps我得到确定814级的对象。我可以运行bwmorph(D,'remove');和我得到的物体的轮廓/周边,但是当我在这个运行bwconncomps我得到827对象 - (不知道在哪里,这些额外的对象都来自这螺丝了我返回来参考基于价值我填充物能力从其“轮廓中拉出)。

基本上我需要bwmorph的一个版本(D,'remove'),它会留下与原始二进制图像的bwconncomps相同数量的连接组件。因此,我可以比较原始二进制文件中的组件#30到bwconncomps中同样#30的轮廓。

希望这是明确的,有什么建议?

由于

enter image description here

回答

1

可以使用bwboundaries找到白色连接的部件,使得每个连接组件具有相应的一组边界的像素边界。

%calculate boundries and generate boundry mask 
B = bwboundaries(im,'noholes'); 
boundriesImage = zeros(size(im)); 
boundriesPixels = cell2mat(B); 
boundriesImage(sub2ind(size(im),boundriesPixels(:,1),boundriesPixels(:,2)))=1; 

%finds the connected component in the original image and in the boundry 
%mask 
CC = bwconncomp(im); 
CC2 = bwconncomp(boundriesImage); 

结果:CC和CC2包含相同数量的连接部件

CC = 

    Connectivity: 8 
     ImageSize: [535 1571] 
     NumObjects: 814 
    PixelIdxList: {1x814 cell} 

CC2 = 

    Connectivity: 8 
     ImageSize: [535 1571] 
     NumObjects: 814 
    PixelIdxList: {1x814 cell} 

而且,每个连接部件CC2的{II}匹配到它的CC {II}如可以通过以下的试验中可以看出结果:

%tests that for each ii, CC{ii} is contained in CC{i} 
CC2MatchesToCC1 = true; 
for ii=1:length(CC.PixelIdxList) 
    if length(intersect(CC2.PixelIdxList{ii},CC.PixelIdxList{ii}))~=length(CC2.PixelIdxList{ii}) 
     CC2MatchesToCC1 = false; 
    end 
end 

结果:

CC2MatchesToCC1 = 

1