从圆圈中去除突出物并侵蚀半径

时间:2015-04-18 07:19:35

标签: matlab image-processing

请有人告诉我如何仅使用形态学操作从这个图像中删除突出物。另外,我想将圆(白色)半径减少5个像素。我知道我们可以通过使用侵蚀来做到这一点,但应该是结构元素(磁盘类型)半径应该是多少以及我们应该为所选半径执行多少次迭代。

我的意思是我们可以有结构元素se = strel(' disk',5)并执行一次迭代或se = strel(' disk',1)并执行5次迭代。

enter image description here

2 个答案:

答案 0 :(得分:5)

Matlab有一个简单的功能,你可以这样做。您可以使用morphological open operationmorphological erode operation来实现此目的。代码可以在下面找到。

I = imread( 'O3Z7j.jpg' );
figure; imshow( I )
D = imopen(I,strel( 'disk', 50 ) );
figure; imshow( D )
E = imerode(D,strel( 'disk', 5 ) );
figure; imshow( E )

基本上,正如维基描述的那样,morphological open是“集合A侵蚀的扩张”,其中erosion is defined here。要创建结构元素内核,可以使用strel( 'disk', n )定义半径为n的光盘。

结果如下所示。

enter image description here

这是侵蚀前的图像。

enter image description here

此处显示之前的图像。

enter image description here

编辑:效果

>> sum( sum( I>128 ) )
ans =
      227675
>> sum( sum( D>128 ) )
ans =
      227173
>> 227675 - 227173
ans =
   502

编辑2:为新要求添加了imerode。

答案 1 :(得分:5)

假设您的图像位于BW数组中,您可以使用bwdist找到主磁盘的中心,然后找到相对于到中心的距离正常分布的像素。 / p>

在实践中,这给出了:

tol = 25;

% --- Get the center
D = bwdist(1-BW);
[~,I] = max(D(:));
[y, x] = ind2sub(size(BW), I);

% --- Find distances
[Y, X] = find(BW);
J = find(BW);
[d2, K] = sort((X-x).^2 + (Y-y).^2);
z = 1:numel(d2);

f = fit(z', d2, 'poly1');
I = (d2 > z'*f.p1 + f.p2 + tol);

BW(J(K(I))) = 0;

结果:

enter image description here

你可以调整参数tol或多或少地侵蚀突出物,但它不应低于20,否则你要删除主盘的像素。

最佳,