Code covered by the BSD License  

Highlights from
bmorph - binary morphological transforms

5.0

5.0 | 1 rating Rate this file 21 Downloads (last 30 days) File Size: 152.49 KB File ID: #26493
image thumbnail

bmorph - binary morphological transforms

by tudor dima

 

27 Jan 2010 (Updated 30 Apr 2012)

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

| Watch this File

File Information
Description

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  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
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?

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.

28 Apr 2012 tudor dima

@Alexander
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!)

Please login to add a comment or rating.
Updates
30 Apr 2012

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

Tag Activity for this File
Tag Applied By Date/Time
image processing tudor dima 27 Jan 2010 10:53:06
morphology tudor dima 27 Jan 2010 10:53:06
erosion tudor dima 27 Jan 2010 10:53:06
dilation tudor dima 27 Jan 2010 10:53:06
binary tudor dima 27 Jan 2010 10:53:06
morphological transforms tudor dima 30 Apr 2012 11:23:30
binary erosion tudor dima 30 Apr 2012 11:23:30
binary dilation tudor dima 30 Apr 2012 11:23:30
image erosion tudor dima 30 Apr 2012 11:23:30
iamge dilation tudor dima 30 Apr 2012 11:23:30

Contact us at files@mathworks.com