imerode/imdilate use convolution?

13 visualizzazioni (ultimi 30 giorni)
Paul Safier
Paul Safier il 15 Gen 2025
Commentato: Paul Safier il 15 Gen 2025
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!

Risposta accettata

Matt J
Matt J il 15 Gen 2025
Modificato: Matt J il 15 Gen 2025
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.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by