is an ellipse-shaped structuring element possible
2 views (last 30 days)
Show older comments
I was wondering if it is possible to create an ellipse-shaped structuring element in matlab?
0 Comments
Accepted Answer
DGM
on 5 Oct 2021
Edited: DGM
on 5 Oct 2021
It's possible, just not with strel().
% build test image
testsz = [35 35]
A = false(testsz);
A(ceil(testsz(1)/2),ceil(testsz(2)/2)) = true;
% specify filter size
filtsz = [15 25];
% a flat disk strel (not quite a circle)
s0 = strel('disk',6);
B0 = imdilate(A,s0);
% stretch out the prior filter (not quite an ellipse)
s1 = imresize(s0.Neighborhood,filtsz);
B1 = imdilate(A,s1);
% make a strel from a numeric filter
% this uses fkgen() from MIMT, since fspecial() can't do this
s2 = simnorm(fkgen('disk',filtsz))>0;
B2 = imdilate(A,s2);
% make a strel from scratch
szf = round((filtsz+1)/2)*2-1; % round to nearest odd integer
[xx yy] = meshgrid(1:szf(2),1:szf(1));
s3 = ((xx-ceil(szf(2)/2))/(szf(2)/2)).^2 + ((yy-ceil(szf(1)/2))/(szf(1)/2)).^2;
s3 = s3<1;
B3 = imdilate(A,s3);
C = cat(2,B0,B1,B2,B3);
imshow(C);
I'm sure there are other ways as well.
MIMT can be found on the File Exchange.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!