imerode/imdilate use convolution?
4 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Matt J
on 15 Jan 2025
Edited: Matt J
on 15 Jan 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)
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!