imerode/imdilate use convolution?

조회 수: 14 (최근 30일)
Paul Safier
Paul Safier 2025년 1월 15일
댓글: Paul Safier 2025년 1월 15일
Do imerode and imdilate use a convolution (e.g. conv2) under the hood? The source code is not available with their respective .m files.
If they do not, what is the algorithm and could those operations also be accomplished with a convolution? If they do, what is the kernel?
Thanks!

채택된 답변

Matt J
Matt J 2025년 1월 15일
편집: Matt J 2025년 1월 15일
No, imdilate is a sliding window max() operation, which is nonlinear, and therefore not, in general, a convolution. Similarly imerode is a sliding min() operation.
That said, for the special case of a binary image BW and a binary structuring element, you could use a convolution as the workhorse of the computation. For example, out1 and out2 give the same result in the following,
BW=randi([0,1],100,100);
k=randi([0,1],3,3);
out1 = imdilate(BW,k);
out2 = convn(BW,k,'same')>0;
isequal(out1,out2)
ans = logical
1
Whether the underlying code gives special treatment to this special case and exploits convolution in this way is not clear since, as you said, the code is not divulged to us.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by