Code covered by the BSD License  

Highlights from
color image segmentation


3.3 | 4 ratings Rate this file 84 Downloads (last 30 days) File Size: 259 KB File ID: #29512
image thumbnail

color image segmentation



24 Nov 2010 (Updated )

segment color image robust to texture

| Watch this File

File Information

An implementation of [1], it works in follows:
1. Compute the Jmap.
2. Compute the valleys of Jmap.
3. Valleys growing as the oversegmentation.
4. Region merging.
Example usage:
%labels = colorImgSeg('images\sflowg.jpg', 12, 5, 10,0.35, 0.02, 0.88);
To run the code, you have to firstly generate the necessary dlls in
"local_min", "Jmap", "seededRegionGrowing" and "Region_merging"
in each folder, run the corresponding compling m-file to generate dlls, which are:
local_min_complie, Jmap_complie, seededRegionGrowing_complie, and RegionMerging_complie respectively.And then copy the corresponding dlls to the parent directory
[1]Yining Deng, B.S. Manjunath, Hyundoo Shin, "Color Image Segmentation,"
 cvpr, vol. 2, pp.2446, 1999 IEEE Computer Society Conference on Computer
 Vision and Pattern Recognition (CVPR'99)- Volume 2, 1999

The author wish to thank Sebastien Paris for his detailly comments on compling and his useful suggestions to improve the code.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
16 Jun 2014 Anshul Mehra  
11 Oct 2013 Sabarinathan Vadivelu  
29 Nov 2012 Nidhi

I am getting an error ----
"Undefined function or method 'Region_merging' for input arguments of type 'double'."
while my all other functions(Jmap,seederegiongrowing etc..) are running successfully..There is no error in compilatons...please help me asap...:(
Thanxxx aton in advance.

04 Sep 2012 Han  
04 Sep 2012 Han  
24 Apr 2012 Orange

Hello, Su. I use Matlab 2010a and run the Jmap_Complie. It showed:

Error: Could not find the compiler "cl" on the DOS path.
Use mex -setup to configure your environment properly.

D:\MATLAB\BIN\MEX.PL: Error: Unable to locate compiler.

??? Error using ==> mex at 222
Unable to complete successfully.

Error in ==> Jmap_complie at 2
mex scale_sum.cpp

What's the problem? How shall I do now? Thank you very much!

03 Aug 2011 Su Dongcai

seems that your are using opencv?
LINK : error LNK2001: unresolved external symbol mexFunction
% cv.lib highgui.lib cvaux.lib cxcore.lib .
try to add the above lib files using
#pragma comment(lib, "*.lib")to your project

03 Aug 2011 Petri

Trying to compile in Windows 64 bit, problems with all the *complie.m-files :
LINK : warning LNK4001: no object files specified; libraries used
LINK : error LNK2001: unresolved external symbol mexFunction
% cv.lib highgui.lib cvaux.lib cxcore.lib @C:\Users\ptleskin\AppData\Local\Temp\mex_skVj7U\mex_tmp.rsp : fatal error LNK1120: 1 unresolved externals

C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: Link of 'local_min.mexw64' failed

Anyone has a solution?

02 Mar 2011 hailong zhao

oh,the last question has solved!

02 Feb 2011 Su Dongcai

Hi arzarm:
Make sure you have run Jmap_complie, and copy the scale_sum.dll to the current directory.

26 Jan 2011 azarm

i tried to implement the m.file in MATLAB.
labels = colorImgSeg('test.jpg', 12, 5, 10,0.35, 0.02, 0.88);

but i received the following error:

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

can anybody help??

28 Nov 2010 Su Dongcai

Hi Sebastien Paris:
Thanks again for your comments, Jmap = Jmap ./ scale_sum(ones(size(Jmap)));
is to remove the boundary affect of Jmap, otherwise the pixels near the boundary would have smaller j-value. Actually the kmeans should be replace with a function that quantilize colors into finite levels, that's a matlab build-in function but I forget its name. I'll be appreciate if someone could remind me.

28 Nov 2010 Sebastien PARIS

A crash seems coming from your scale_sum mex file. However this mex file is only used in cmp_Jmap in the line
Jmap = Jmap ./ scale_sum(ones(size(Jmap)));

This line seems to be useless since scale_sum(ones(size(Jmap))) = ones(size(Jmap)), you can comment it.

Other point, you should change you kmeans algorithm. You can find in FEX a lot kmeans algorithm with mex-interface. So you'll go faster and be independant of the statistic toolbox.

28 Nov 2010 Sebastien PARIS

Comment as below and it would compile :

#include "stdafx.h"
#include "local_min.h"
#include "mex.h" //MATLAB API

#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmex.lib")

DWORD ul_reason_for_call,
LPVOID lpReserved
switch (ul_reason_for_call)
return TRUE;

// This is an example of an exported variable
LOCAL_MIN_API int nLocal_min=0;

// This is an example of an exported function.
LOCAL_MIN_API int fnLocal_min(void)
return 42;

// This is the constructor of a class that has been exported.
// see local_min.h for the class definition

27 Nov 2010 Su Dongcai

Hi Sebastien Paris :
Thanks for your report, yes ,when complie mex local_min.cpp c_local_min.cpp, including <set> fail in my matlab version.

27 Nov 2010 Sebastien PARIS

for each folder after commenting
SEEDEDREGIONGROWING_API int nSeededRegionGrowing=0;

// This is an example of an exported function.
SEEDEDREGIONGROWING_API int fnSeededRegionGrowing(void)
return 42;

mex seededRegionGrowing.cpp c_RegionGrowing.cpp
mex scale_sum.cpp
mex Region_merging.cpp c_Region_merging.cpp disjoint_elt.cpp Disjoint_set.cpp Edge.cpp extract_edges.cpp public_functions_lib.cpp

mex local_min.cpp c_local_min.cpp

works with msvc2008 express. Do you really need the STL ?

26 Nov 2010 Su Dongcai

Hi S├ębastien:
The file is complied under vc60 in windows, so it may not works in other operating environment. I tried to complie it using "mex" in matlab, but it cannot include the stl.

26 Nov 2010 Sebastien PARIS


I tried in first attempt to compile via dsw files with VS2008 express + XP 32 without success. Then I recompile each files via the mex command after commenting :
// This is an example of an exported variable
LOCAL_MIN_API int nLocal_min=0;

// This is an example of an exported function.
LOCAL_MIN_API int fnLocal_min(void)
return 42;
in each files.
The compilation works but the demo crash...

You should provide us a matlab script to compile each files to be independant of Windows and MSVC.

30 Nov 2010

replace the kmeans function with rgb2ind, supply the compling m-files

06 Dec 2010

modify the description make the instruction correctly to the new file

Contact us