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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2024a

質問済み:

2025 年 1 月 15 日

コメント済み:

2025 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by