This function performs binary erosion or dilation.
It is faster than imerode.m and imdilate.m -- by more than an order of magnitude for any structuring element other than 'square' or 'disk' .
The only time it is slightly slower (about 10%) is for very small 'square' or 'disk' strels only.
Moreover, ’disk’ structuring elements in Matlab are actually octagonal, and often times a
true ’circular’ element is necessity.
It also comes in very handy when you don't have the Matlab Image Processing Toolbox :-)...
The function also allows very fast iterative calls which re-use the work done at previous iterations. (for instance when sweeping the size/size+shape of the structuring element while looking for a certain effect, a threshold in image statistics, etc.)
This re-use will make the speed increase compound exponentially, and one can also break the execution when desired.
For 2-3M pix images and strels in the range of 10-20 pixels the speed increase can be around 20x - 100x (depending on the machine cache, slightly on strel shape, etc.), with higher values as the image and/or strel size increase.
IMG_OUT = BMORPH(IMG_IN, SE, DilateNotErode, , ObjStopAtEdge)
IMG_DIL = BMORPH(IMG_IN, SE, true); % dilate
IMG_ERO = BMORPH(IMG_IN, SE, false); % erode
% erode assuming the objects stop at edge :
IMG_ERO = BMORPH(IMG_IN, SE, false, , true);
For iterative calls and more info on execution speed see the help in bmorph.m and the attached .pdf file.
tudor dima (2021). bmorph - binary morphological transforms (https://www.mathworks.com/matlabcentral/fileexchange/26493-bmorph-binary-morphological-transforms), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!