Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 填充二值图像中未完全闭合的区域_Matlab_Image Processing_Matlab Cvst - Fatal编程技术网

Matlab 填充二值图像中未完全闭合的区域

Matlab 填充二值图像中未完全闭合的区域,matlab,image-processing,matlab-cvst,Matlab,Image Processing,Matlab Cvst,在MatLab中,我有一个二值图像,我试图填补一个漏洞。问题是,该地区大部分(但不是全部)是封闭的。是否有任何现有的视觉处理功能可以做到这一点?我必须写我自己的算法吗 原始/所需 另一个独立的问题是,我在检测二值图像中的细尾巴结构时遇到困难。我需要移除这些类型的结构,而不移除它所连接的更大的主体。是否有任何现有的视觉处理功能可以做到这一点?我必须写我自己的算法吗 原始/所需 在第一个示例中,您可以使用先进行扩张,然后进行侵蚀,以闭合这些边。然后,您可以跟进以完全填写它 img = imre

在MatLab中,我有一个二值图像,我试图填补一个漏洞。问题是,该地区大部分(但不是全部)是封闭的。是否有任何现有的视觉处理功能可以做到这一点?我必须写我自己的算法吗

原始/所需

另一个独立的问题是,我在检测二值图像中的细尾巴结构时遇到困难。我需要移除这些类型的结构,而不移除它所连接的更大的主体。是否有任何现有的视觉处理功能可以做到这一点?我必须写我自己的算法吗

原始/所需


在第一个示例中,您可以使用先进行扩张,然后进行侵蚀,以闭合这些边。然后,您可以跟进以完全填写它

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');
类似地,对于第二组图像,可以使用(先腐蚀,然后膨胀)去除尾部

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));

更新

如果你想要上面“闭合”图像中央开口的质心,你可以通过从
填充的
中减去
闭合的
,得到一个正是这个开口的掩模

% 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)];

任何这样的算法都会砍掉腿。那没关系。我只需要主体区域就行了!非常感谢你。我已经努力解决这个问题3个小时了@USSR315340如果它为你工作,考虑将它标记为帮助他人解决类似问题的解决方案。是否有可能找到“闭合图像”的黑色封闭圆的质心坐标?@user3315340更新了该解决方案。