File Exchange

image thumbnail

Grayscale Dilation and Erosion

version (5.28 KB) by Luigi Rosa
A very fast implementation.


Updated 19 Nov 2003

View License

The zip file includes:
- readme.txt this file
- gdil.c ----> a c file which must be mex compiled
- gerod.c ---> a c file which must be mex compiled
- graydil.m --> the m function (dilation)
- grayero.m --> the m function (erosion)
- provatempo.m ---> many examplex of use

Grayscale erosion and dilation: a very fast implementation.

We have optimized execution time of grayscale erosion and dilation. Our functions take advantage of MATLAB's decomposition of structuring

graydil(im,se) to perform dilation
im is the input 2D matrix (uin8, uint16, uint32 or double)
se the structuring element (logical or strel)

grayero(im,se) to perform erosion
im is the input 2D matrix (uin8, uint16, uint32 or double)
se the structuring element (logical or strel)

Memory management is not optimized ( our routines can generate
overflow memory error) but execution time is 2, 3, 4 or 5 times
smaller than MATLAB's one.

Please contribute if you find this software useful.
Report bugs to

Cite As

Luigi Rosa (2020). Grayscale Dilation and Erosion (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

Fardin Jalil Piiran

Adrien Mau

siyu lei

Zachary Milne

Nevermind, I didn't before realize how to use strel to convert my desired se to one usable by imdilate and imerode. I know now how to do so. I see that your code speeds up these morphological operations.

Zachary Milne

Is these codes really grayscale erosion and dilation, or they binary erosion and dilation? I ask because it seems like these codes still require se to be binary. Grayscale erosion and dilation does not require that se be binary, only grayscale. I don't see how these codes are an improvement to imerode and imdilate. Any explanation will be very helpful.


Fast and efficient..Great job

kiran hidayat

Tran Cong Binh

I very need this program to research

surya s

pretty fast, more than 3 times fold. By chance, do you have a version for binary images also?

Mehdi Hussain

Very nice i got lot of idea thanks sir
sir if possible then send me "Iris Recognition" type material or article
i wll be waiting

Len Russo

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!