File Exchange

image thumbnail

DEM: Diffused expectation maximisation for image segmentation

version (740 KB) by Giuseppe Boccignone
Color image segmentation using a variant of the Expectation-Maximization (EM) algorithm.


Updated 18 Jun 2012

View License

Description: The code is a simple Demo of the Diffused Expectation Maximisation (DEM) algorithm

for image segmentation as described in the paper

G Boccignone, M Ferraro, P Napoletano (2004). "Diffused expectation maximisation for image segmentation", Electronics letters 40 (18), 1107-1108.

The method classically models a color image as a finite Gaussian mixture, where each mixture component corresponds to a region class and uses a maximum likelihood approach to estimate the parameters of each class, via the expectation maximisation (EM) algorithm, coupled with anisotropic diffusion on classes, in order to account for the spatial dependencies among pixels.

To create the software library and run the demos:

1) unpack the compressed zip file in your working directory and cd to such directory

you will find the following directories:

- /visualization: some visualization tools

- /mex: mex files

- /img: color images to be processed

- /results: to store segmentation results

- /doc: the EL paper

2) download and install the netlab package in the same directory


3) build the mex files, here we are providing only precompiled mexmaci64 (MacOS, 64 bit Matlab)

>> cd mex

>> mexall

[you may need to modify the mexall.m script under Windows OS]

4) Run demo program

>> cd ..

>> showGmmDEM

The demonstration program showGmmDEM will only operate on color images

The script:

(1) loads a color image from the img directory

(2) runs a classic Expectation-Maximization based segmentation by calling the Netlab function gmmem()

(3) runs the DEM variant by calling the function gmmdem()

(4) displays the segmentation outputs together with the original image

Main functions:

- gmmdem(): this implements the DEM algorithm. Basically a variant of the Netlab gmmem function implementing Expectation Maximization for learning a Gaussian Mixture Model. Here a D-step is interleaved with the E-step and M-step of the classic EM algorithm All parameters are the same as netlab gmmem except for diffoptions, the structure storing the diffusion parameters:

- diffoptions.iter: number of iterations for the D-step

- diffoptions.kappa: Perona-Malik equation conduction coefficient 20-100

- diffoptions.lambda: Perona-Malik equation: discrete step, max value of .25 for stability

- diffoptions.PeronaMalikEq: Setting the diffusion type:

= 1 Diffusion equation 1 favours high contrast edges over low contrast ones.

= 2 Diffusion equation 2 favours wide regions over smaller ones

- normalise() and related mex functions: these are from Kevin Murphy KPMtools

- sc(), label(): visualization functions

Cite As

Giuseppe Boccignone (2021). DEM: Diffused expectation maximisation for image segmentation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Image Analyst

Requires the MATLAB Compiler toolbox. If you don't have that, it won't work. Also requires you to download an additional toolbox from and evidently that web site no longer exists. Basically this submission is completely unusable.

ankita taparia

build the mex files, here we are providing only precompiled mexmaci64 (MacOS, 64 bit Matlab)

>> cd mex

>> mexall

[you may need to modify the mexall.m script under Windows OS]

what changes to be done for windows 64 bit?

ankita taparia

i am getting these errors
Error using chol
Matrix must be positive definite.

Error in gmmactiv (line 55)
c = chol(mix.covars(:, :, j));

Error in gmmpost (line 25)
a = gmmactiv(mix, x);

Error in gmmem (line 78)
[post, act] = gmmpost(mix, x);

Error in showGmmDEM (line 215)
[mixem, options, errlog] = gmmem(mix, train_data', options); %Netlab stuff

Shengnan Liu

The results from EM is all zeros...
But in general it works now, I will look into the code further.

Ahmed Gad

Undefined function 'gmm'
Undefined function 'gmminit'
Undefined function 'gmmem'
and others.
What can I do?

MATLAB Release Compatibility
Created with R2010b
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!