填写未完全关闭的二进制图像区域

use*_*340 3 matlab image-processing matlab-cvst

在MatLab中,我有一个二进制图像,我试图填补一个洞.问题是该区域大部分(但并非完全)关闭.是否有任何现有的视觉处理功能可以做到这一点?我必须编写自己的算法吗?

原创/期望

在此输入图像描述 在此输入图像描述

另一个单独的问题是我在二进制图像中检测薄尾状结构时遇到问题.我需要移除这些类型的结构,而无需移除它附着的较大的主体.是否有任何现有的视觉处理功能可以做到这一点?我必须编写自己的算法吗?

原创/期望

原始图像 期望的图像

Sue*_*ver 5

在第一个示例中,您可以使用imclose扩张,然后进行侵蚀以关闭这些边缘.然后你可以跟进imfill以完全填写它.

img = imread('http://i.stack.imgur.com/Pt3nl.png');
img = img(:,:,1) > 0;

% You can play with the structured element (2nd input) size
closed = imclose(img, strel('disk', 13));
filled = imfill(closed, 'holes');
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 同样,使用第二组图像,您可以使用imopen(侵蚀,然后扩张)来移除尾部.

img = imread('http://i.stack.imgur.com/yj32n.png');
img = img(:,:,1);

% You can play with the structured element (2nd input) size
% Increase this number if you want to remove the legs and more of the tail
opened = imopen(img, strel('disk', 7));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

更新

如果你想"关闭"上述图像的中心孔的心,你可以得到一个面膜这仅仅是这种开放减去closedfilled.

% Find pixels that were in the filled region but not the closed region
hole = filled - closed;

% Then compute the centroid of this
[r,c] = find(hole);
centroid = [mean(r), mean(c)];
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述