Code covered by the BSD License  

Highlights from
bmorph - binary morphological transforms


4.5 | 2 ratings Rate this file 18 Downloads (last 30 days) File Size: 152 KB File ID: #26493
image thumbnail

bmorph - binary morphological transforms



27 Jan 2010 (Updated )

Fast binary erosion and dilation, with even faster iterative calls.

| Watch this File

File Information

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.

Simple call:
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.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
29 Oct 2014 tudor dima

Different results are obtained when different strels are used. Incidentally, this is exactly why this box was built, for the "circular" strel in matlab is actually octagonal. It is stated in the first paragraph of the description.

As for the difference between the matlab dilation/erosion operations and this implementation you could try reading the included .pdf file.

No, I have no suggestions on grayscale morphology.

23 Oct 2014 Hassan Naseri

Thanks for the really fast code.
However, I do not get the expected results as the original imdilate. Would you please tell the difference between the standard dilation/erosion operations and your implementation in terms of functionality?
Another question is that, do you have a speed-up suggestion for grayscale morphology?

28 Apr 2012 tudor dima

The structuring element is passed to this function (or to imdilate/imerode, that is).
I am not sure how is it done in Matlab (it's a .mex, twice wrapped :-))

What I suspect it makes the interpreted bmorph to run faster than the MEX is that I do a contour detection on both the image and the strel, then only update those values, the strel is not swept across the whole image.

Until now it only allowed symmetrical strels, but I have recently posted the new version which fixed this. (Thanks to Sean Sklios for the provided test data and also for the push!)

08 Dec 2011 Alexander

Great code! Very useful if you don't have the Image Processing Toolbox.

One question: how do you set up the 'circular' structuring element? This seems to be where you get the speed advantage, but I'm not sure how you implement. Thanks.

07 Nov 2011 ssklios Sklios

much faster! This is exactly what I am looking for to use in my image processing code. However, it did not give the same results as imerode for me. Help please?

30 Apr 2012

v.0.3b, 29.04.2012
- allow asymmetrical strels
- small speed improvements

Contact us