is an ellipse-shaped structuring element possible
3 次查看(过去 30 天)
显示 更早的评论
采纳的回答
DGM
2021-10-5
编辑:DGM
2021-10-5
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!