File Exchange

image thumbnail

color image segmentation

version 1.3.0.0 (259 KB) by Su Dongcai
segment color image robust to texture

4 Downloads

Updated 06 Dec 2010

View License

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
reference:
[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

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

Cite As

Su Dongcai (2020). color image segmentation (https://www.mathworks.com/matlabcentral/fileexchange/29512-color-image-segmentation), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (21)

jack joseph

Great package, yet it would be better if a tiny bug can be fixed.

In the file public_functions_lib.h, line 19 and line 21:

const num_pixels

should be replaced with

const int num_pixels

similar change should be made in public_functions_lib.cpp as well.

Old C++ compilers might assume int where type definition is missing, but newer compilers will throw an error.

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.

Han

Han

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!

Su Dongcai

*Petril:
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

Petri

Hi
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?

oh,the last question has solved!

Su Dongcai

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

azarm

HI,
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??

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.

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.

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")

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
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
CLocal_min::CLocal_min()
{
return;
}
*/

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.

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 ?

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.

Hello,

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.
Sébastien

Updates

1.3.0.0

modify the description make the instruction correctly to the new file

1.2.0.0

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

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