Background
Recently I have decided to explore tracking from 3D point clouds extracted from stereo vision cameras. Step 1: Extract 3D point cloud from stereo vision cameras. So right now I’m implementing Segment-Based Stereo Matching Using Belief Propogation and Self-Adapting Dissimilarity Measure” by Klaus, Sormann, and Karner. This paper is defined by the source on stereo vision to be the best one around. This paper has two parts. Part 1: Segment the image. Part 2: Compute disparity (and depth) from the segments. Well, today I finished Part 1.

First Try
The authors refer to a mean-shift segmentation algorithm presented in Mean Shift: A Robust Approach Toward Feature Space Analysis” [pdf] by Comaniciu and Meer to do the image segmentation. This paper (unlike some of my own previous work) leans towards oversegmentation of an image. Meaning that you prefer to get lots of little bits rather than the “right object” after the algorithm has run.
Well, after looking over the paper and getting a grasp for the mathematics, I took a crack at implementing it. Easily done… HOWEVER, my first attempt, written in Matlab, was painfully slow. (For a simple image it took 6 hours to run!) So, I got on the internet and came up with a better solution!
The Solution
Some great guys at Rutgers University implemented this paper in C++ and made the code available to the public under the name EDISON. (there’s also a nice GUI that goes along with this if you want to just play to see if these codes will work for you). Okay, so I had C++ codes that worked well (only 2 sec to do an image rather than 6 hours). The next step was to bring the code into Matlab.

These were the type of results I was trying for
I cracked my knuckles and got ready to write a MEX wrapper for this EDISON code. Then I said to myself, “Self, maybe you should check the ‘net first.” Turns out I had a good point. I found the website of Shai Bagon. Mr. Bagon had already made the MEX wrapper! Awesome.
I downloaded the codes and put them together. Mr. Bagon’s stuff worked right out of the box, although it would have saved me about an hour if I would have had this information (alternative readme.txt for Matlab Interface for EDISON). I also wrote my own wrapper-wrapper so that I could process grayscale images, and do simpler calls to accomplish what I wanted. If you’d like the code, download my wrapper-wrapper here (msseg.m).
Results
Here is a sample of the output of this algorithm. The first image is a regular photo of some posed objects. The second image is the segmented version. Notice how the regions of the image are much, much more constant. This image has been broken into “tiles” of constant color.

The original image (part of a standard pair of test images).

The segmented image (ready to be processed in step 2)
Conclusion
Don’t re-invent the wheel. Taking a first crack at the implementation was good, and it helped me understand the algorithm. However, there was no need for me to spend a week tweaking it to be super-fast or two days getting the Matlab interface working. These things had already been done! It feels nice to knock out a task that you thought was going to take a week in a few hours : ) Stay tuned for the stereo part of this paper coming soon. Then maybe people will be writing about my page!
Where can I get the code in matlab?
you are missing the assignment of L in your wrapper.
Thanx buddy,
This post was very helpful to me.
thanks.
This is a good article.
Thanks ..The article that i was looking for :)
Keep on posting, Man !
can i get a source code of it plz
can i get a source code of it plz
Thanks. It’s been very helpful!
can i get the code for mean shift method
can i get matlab code this? kindly send me…
Can you helm me get the code in c++?
I can not get anywhere.
best regards,
Can i get the code in matlab?
Can I get the code for mean shift segmentation?
plz send code for mean shift . thank u for info
Hi nowaday, i study segmentation using matlab
but it is very hard to me
so if you can, Can i get the code in matlab?
hello, hai, please send code for mean shift segmentation. tqvm
hello could I get the code for mean shift segmentation please??
Hello Sir,
Can I get the code for mean shift segmentation.
Please reply me.
Thanks
Great post! I got the mean shift Matlab interface working and it’s really great. I used Matlab 2015a with the windows SDK 7.1 compiler. I did get some compiler errors initially due to some of the .cpp and .h files having the Mac end-of-line format and also had to typecast an input to the c++ pow() function to a double. After these fixes, it compiled without any problems.
@bengie
Hey bengie! I need help. How should i start? Do i need to C++ platform as well for this code or just matlab?
Hi, I’m very interesting on this code, however, my computer is window 64bit, and when I use MATLAB to compile this edison wrapper, it shows ‘Mac file format detected: please convert the source file to either DOS or UNIX format’
So, I wonder how can I fix that problem?
sir can i get the code please…kindly send me the matlab code to my email id
Hi !
Great article, can you send me the matlab code for this ?
Thanks !
getting error error “C4335: Mac file format detected: please convert the
source file to either DOS or UNIX format” I don’t how to remove it. Please help
can I get the sorce code in matlab, please?