Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Protrusion from A circle and Erode Radius [closed]

Please anybody tell me how to remove only the protrusion from this image using just the morphological operations. Also I want to reduce the circle (white color) radius by 5 pixels. I know we can do that by using erosion but what should be the structuring element's(disk type) radius should be and how many iterations should we perform for the selected radius.

I mean can we have structuring element se =strel('disk',5) and perform one iteration or se = strel('disk',1) and perform 5 iterations.

enter image description here

like image 727
Navdeep Avatar asked Dec 30 '25 13:12

Navdeep


2 Answers

Matlab has a simple function for you to do this. You can use a morphological open operation and morphological erode operation to achieve this. The code can be found below.

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 )

Essentially as Wiki describes it, morphological open is the "dilation of the erosion of a set A", where erosion is defined here. To create the structuring element kernel, you can use strel( 'disk', n ) to define a disc of radius n.

The result is shown here.

enter image description here

Here is the image before the erosion.

enter image description here

The before image is shown here.

enter image description here

EDIT: Performance

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

EDIT 2: Added imerode for new requirement.

like image 178
krisdestruction Avatar answered Jan 01 '26 05:01

krisdestruction


Assume your image is in a BW array, you can find the center of the main disk with bwdist and then find the pixels that are anormally distributed with respect to the distance to the center.

In practice, this gives:

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;

and the result:

enter image description here

You can tune the parameter tol to erode more or less the protrusion, but it should not be below 20 otherwise you with remove pixels of the main disk.

Best,

like image 38
Ratbert Avatar answered Jan 01 '26 03:01

Ratbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!