MATLAB:隔离二进制图像中感兴趣区域的周长:bwmorph 问题

MATLAB: isolating perimeters of regions of interest in binary image: bwmorph issues

我有一个二进制图像(已附加),其中连接的组件用 bwconncomps 隔离。我正在尝试识别这些组件中的每一个的轮廓,但在某种程度上我仍然可以参考填充的对象-(我使用轮廓作为灰度图像上的遮罩来提取一些值,然后根据那个对填充的原始感兴趣区域执行操作的值)

当我 运行 bwconncomps 在附加图像上时,我识别出 814 个对象。我可以 运行 bwmorph(D,'remove');我得到了对象的 outlines/perimeters 但是当我 运行 bwconncomps 对此我得到了 827 个对象-(不确定这些额外的对象来自哪里,这搞砸了我返回填充的能力基于我从其轮廓中提取的值的对象)。

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

希望这很清楚,有什么建议吗?

谢谢

你可以使用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