File Exchange

image thumbnail

EM-MPM Image Segmentation Algorithm

version (4.41 KB) by Alceu Costa
Segments a grayscale image using the EM-MPM algorithm.


Updated 09 Sep 2013

View License

Is = emmpm(I) returns an uint8 matrix Is representing the segmented image. Each entry of Is is an integer between 1 and 'regions'. 'regions' defines in how many regions the image I will be segmented.

EMMPM defines optional arguments:

EMMPM(I, regions, steps, mpmSteps, coolMax, coolInc)

steps: Defines the number of iterations in the segmentation process (default = 5);
mpmSteps: Defines the number of repetitions of the MPM algorithm at each iteration of the segmentation process (default = 1);

The EM/MPM method is iterative that stabilizes after a number of iterations. Usually, a higher number of iterations yelds better segmentation but increases segmentation time. Use a lower values for 'steps' and 'mpmSteps' to reduce time.

coolMax: Defines the maximum cooling rate (default = 1.2);
coolInc: Defines how much the cooling rate is incremented at each iteration (default = 0.025).

coolMax and coolInc control the segmentation cooling rate. Higher cooling rates stabilize the segmentation process. In early stages of segmentation, it is desired to have a low cooling rate.


% Binary segmentation.
I = imread('coins.png');
Is = emmpm(I, 2);
imshow(Is, []); % Show the segmented image.

% 5 regions segmentation.
I = imread('peppers.png');
Is = emmpm(I, 3);
imshow(Is, []); % Show the segmented image (note that emmpm does not use color information).

Example image from

Cite As

Alceu Costa (2020). EM-MPM Image Segmentation Algorithm (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Alceu Costa

Thank you for the reference Akshay Gore.

I implemented this EM-MPM algorithm as part of an undergraduate course based on a masters dissertation of another student, so there may be differences between the algorithm described in the article and my implementation.

Here is a link to the masters dissertation (in Portuguese):

Alceu Costa

Hi Jonathan, can you provide a link to the image or send it via email?

This way I can check if there is a bug in my code or if the image is a case were this segmentation algorithm will not work.


I got a black image by this code!!!!!


Alceu Costa

Hi Nagaraj,

Which command are you using to show the segmented image? For example, when you use the imshow() function, don't forget the second parameter (the color map).

The color map is necessary because the segmented image pixels will be in the range [1..N], where N is the number of regions in the segmented image.

I plan to make a blog post giving examples on how to use the EM/MPM code.

Nagaraj H

Please send the link to/file supporting files for understanding the code. Please also include some images which you have tested.

Nagaraj H

I tried this code on brain MR image of oasis database in gif format. It is showing completely black image as output. I tried it on other general images but the result is same. Is it necessary to make some adjustments for running the code?

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