2016-06-14 37 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