从圆和侵蚀半径中移除突起

Removing Protrusion from A circle and Erode Radius

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

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

Matlab 有一个简单的函数可以让你做到这一点。您可以使用 morphological open operation and morphological 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 )

基本上就像 Wiki 描述的那样,morphological open is the "dilation of the erosion of a set A", where erosion is defined here。要创建结构元素内核,您可以使用 strel( 'disk', n ) 定义半径为 n.

的圆盘

结果显示在这里。

这是侵蚀前的图像。

此处显示之前的图像。

编辑:性能

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

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

假设你的图像在一个BW数组中,你可以用bwdist找到主圆盘的中心,然后找到相对于到中心的距离呈正态分布的像素.

在实践中,这给出了:

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;

结果:

您可以调整参数tol来或多或少地侵蚀突起,但它不能低于20,否则您将删除主磁盘的像素。

最佳,