Code covered by the BSD License  

Highlights from
color Image Segmentation


4.1 | 13 ratings Rate this file 142 Downloads (last 30 days) File Size: 16.4 KB File ID: #25257
image thumbnail

color Image Segmentation



08 Sep 2009 (Updated )

Segments a color image into regions.

| Watch this File

File Information

This program segments a color image into different regions.
The steps followed for segmentation in this program is as follows:

1. The input color image will be coarsely represented using 25 bins.
2. Coarse representation uses the spatial information from a Histogram based windowing process.
3. K-Means is used to cluster the coarse image data.

Those who are new to Matlab Programming can see the "SampleUsage.m" file for the usage of the script "colImgSeg.m".

Those who are already familiar with Matlab Programming can directly use the script "colImgSeg.m".

Required Products Image Processing Toolbox
MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
13 Apr 2013 mert vatansever

hi Athi,
ı need more explanation about your codes.
so if its possible give me a more more details?
actually ım so new for matlab but ı have a homework about this subject. so pls help me if you can.

more details. more comment about codes. :)


Thanks for this, it is really helpfull

22 Mar 2013 Ashraful Alam

How can i get matlab code in colour image segmentation.

04 Nov 2012 Manini

Hi Athi
I have implemented your code..
i am getting correct output when i run it first time..but when i try to run it next time i am getting this error..
Index exceeds matrix dimensions.

Error in colImgSeg (line 22)

Error in nbinsusage (line 19)
outImg = colImgSeg(inImg, nBins, winSize, nClass);

please help me to resolve the same..

23 Aug 2012 Sabarinathan Vadivelu  
29 May 2012 ljklpsy

May i ask if there is a way to keep the same color for the same region of an image if running kmeans several times? thanks a lot!!!

31 Jan 2012 lbrce


14 Oct 2011 waseem ahmad

hi athi,
i need to find the center of a colored region if u can help me,plz?

03 Aug 2011 Thendral

Hi Athi
When i am running this code i am getting error like this

Error in ==> colImgSeg at 24
s = size(inImg);
Plz help me

18 Jul 2011 AMIT

hi athi
thnx dude
can you plz send me the Literature of this program
it will help me in myproject


09 Jun 2011 Saravanan

Its good,

fusedMap = kmeans(inImg_1D,nClass, 'EmptyAction', 'singleton');

I am working on medical images, where the fusedMap becomes NULL.

Whether its for particular type of images ?

07 Oct 2010 Biao

if the illustration algorithm is more specific, this program will be more honorable!

06 Oct 2010 Biao

thank you so much! it's useful!

08 Jul 2010 Juan Du

Hi Athi,

Thank you. This is very useful tool. I also want to segmenting HSI images. But it does not work with this code. This code seems only works on RGB image. Can you help me to solve the problem?


19 May 2010 zhao qiang  
19 May 2010 zhao qiang

Hi Athi,
Nice contribution.
your program is unstabe ,this is because of the function kmeans,you can try it.
and i want konw what is the meaning of the following statements?

lab = floor(mat(i,j,1)/divis)*(nBins*nBins);
lab = lab + floor(mat(i,j,2)/divis)*(nBins);
lab = lab + floor(mat(i,j,3)/divis);
lab = lab + 1;
TabLabel(lab) = TabLabel(lab) + 1;
sum_lab = sum_lab + lab;
i think this is a weighted action?but why?
look for your reply~

05 Jan 2010 Theodoros Giannakopoulos  
23 Dec 2009 Farie

Hi, I tried your program but got lot of errors, like not in the loop, unused variables. Can you fix it?

29 Nov 2009 Ashok Kumar  
19 Oct 2009 nanang krisdianto

hi Athi

when i am running the code,
Why i have notification like this

??? Input argument "inImg" is undefined.

Error in ==> colImgSeg at 24
s = size(inImg);

14 Sep 2009 jichao zhao

why I have the following error, I do not have Image Processing Toolbox?

??? Undefined function or method 'kmeans' for input arguments of type 'double'.

Error in ==> colImgSeg at 81
fusedMap = kmeans(inImg_1D,nClass, 'EmptyAction', 'singleton');

Error in ==> SampleUsage at 18
outImg = colImgSeg(inImg, nBins, winSize, nClass);

13 Sep 2009 Vignesh

Its working fine. It helps me to understand color histogram fuzzification. Thanks a lot.

12 Sep 2009 Athi

Dear Ramana Murthy,

The output matrix will be same.
But the coloring may differ. Because of default color usage & K-Means.
Am I answered your question?

11 Sep 2009 Venkat R  
11 Sep 2009 Venkat R

Hi Athi,
Nice contribution.
When we run the program on same image, different results are coming. It appears there is some bug in your terminating criterion in clustering. Can you fix it.


07 Jun 2011

Author Info Updated

Contact us