Home > Academics, Research, Tutorials > How to install Greg Mori’s superpixel MATLAB code?

How to install Greg Mori’s superpixel MATLAB code?

This short note aims to show you how to use superpixel code from Greg Mori whose codes are observed to have very good results and used by a bunch of computer vision researchers. However, the installation process can be challenging sometimes ^_^, so I figured it’d be nice if I document the process so that it will be easier for absolute beginners to use the code, and more importantly…I can come back to read when I forget how to do it.

I have MATLAB R2010a installed on my Ubuntu 32-bit 10.04 LTS – the Lucid Lynx

I download Mori’s code, extract the zipped file to a folder called superpixels. The folder is located at
/home/student1/MATLABcodes/superpixels

Next I download the boundary detector code from the link
http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/code/segbench.tar.gz
I extract it to a folder called segbench, then I put it inside the superpixels
/home/student1/MATLABcodes/superpixels/segbench
—————————————————————————–
Here are the instructions of the folders

README (Mori’s)

– Run mex on *.c in yu_imncut directory
– Obtain mfm-pb boundary detector code from
http://www.cs.berkeley.edu/projects/vision/grouping/segbench/
– Change path names in sp_demo.m and pbWrapper.m
– Get a fast processor and lots of RAM
– Run sp_demo.m

README (segbench’s)
(1) For the image and segmentation reading routines in the Dataset
directory to work, make sure you edit Dataset/bsdsRoot.m to point to
your local copy of the BSDS dataset.

(2) Run ‘gmake install’ from this directory to build everything.  You
should then probably put the lib/matlab directory in your MATLAB path.

(3) Read the Benchmark/README file.
———————————————————————————————————————

According to the README instruction
– Run mex on *.c in yu_imncut directory
I run mex on all the .c file in the folder
/home/student1/MATLABcodes/superpixels/yu_imncut
I don’t know why the command mex *.c does not work, so I have to run mex on every file one by one. Each time I run mex, I will get message
Warning: You are using gcc version “4.4.3-4ubuntu5)”.  The version
currently supported with MEX is “4.2.3”.
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
However, it seems to work fine since I can see all the .mexglx files show up in the folder. So I assume I do it correctly and go on the next step.

In this step,
– Obtain mfm-pb boundary detector code from
http://www.cs.berkeley.edu/projects/vision/grouping/segbench/
I got the code already, so I follow the README (segbench’s). Firstly, I do
(1) For the image and segmentation reading routines in the Dataset
directory to work, make sure you edit Dataset/bsdsRoot.m to point to
your local copy of the BSDS dataset.
So, I go to the file /home/student1/MATLABcodes/superpixels/segbench/Dataset/bsdsRoot.m and change the root to
root = ‘/home/student1/MATLABcodes/superpixels’;
which contains the image I want to segment, “img_000070.jpg”

Next, I do (2) in README (segbench’s)
(2) Run ‘gmake install’ from this directory to build everything.  You
should then probably put the lib/matlab directory in your MATLAB path.
Now at the folder, student1@student1-desktop:~/MATLABcodes/superpixels/segbench$
we need to make MATLAB seen in this folder, so we export the MATLAB path
student1@student1-desktop:~/MATLABcodes/superpixels/segbench$ PATH=$PATH:/usr/share/matlabr2010a/bin
student1@student1-desktop:~/MATLABcodes/superpixels/segbench$ export PATH
then use make install, this time I got quite a long message in the terminal
student1@student1-desktop:~/MATLABcodes/superpixels/segbench$ make install
Then you will notice some files in the folder
/home/student1/MATLABcodes/superpixels/segbench/lib/matlab
What you have to do here is to addpath in MATLAB by typing in the command window
addpath(’/home/student1/MATLABcodes/superpixels/segbench/lib/matlab’);

Next, (3) Read the Benchmark/README file. I found that we don’t have to do anything in this step. So just skip this.

Now it’s the last step
Change path names in sp_demo.m and pbWrapper.m
so, go to the folder /home/student1/MATLABcodes/superpixels and change the path
in pbWrapper.m I make the path pointing to ‘/home/student1/MATLABcodes/superpixels/segbench/lib/matlab’
in sp_demo.m I make the path pointing to
‘/home/student1/MATLABcodes/superpixels/yu_imncut’

Now run the file sp_demo.m. Unfortunately you will get some error messages because of a function spmd. This happens because MATLAB 2010a has function spmd of its own which has the number of input argument different from that of spmd from the toolbox. One way to get around this is to change the name of spmd.c in the toolbox to spmd2.c, then compile spmd2.c using mex spmd2.c. Then replace spmd(…) with spmd2(…). If you encounter more errors from this point on, don’t panic, because it’s probably from this spmd issue, so just do the same thing and it will work fine.

That’s it! Enjoy Greg Mori’s code!

——————————————————————————

For windows users, please refer to Thanapong’s blog, whose URL is given below:
http://blog.thanapong.in.th/arah/?p=29

Advertisements
  1. Federico
    March 14, 2011 at 6:06 am

    Hello,

    I followed your notes (thanks) and eventually I changed spmd.c to spmd2.c and I get this weird error:

    ??? Trying to load file
    “superpixels/yu_imncut/spmd2.mexglx”
    while it is being loaded.

    Error in ==> cncut at 49
    W = spmd2(W,dih,dih);

    Error in ==> imncut_sp at 93
    [Vp,S] = cncut(W(p,p),U,nv);

    Error in ==> sp_demo at 45
    [Sp,Seg] = imncut_sp(I,par);

    Did you encounter the same problem? I am on Ubuntu Ubuntu 32-bit 10.10 with R2010a

  2. admin
    March 14, 2011 at 12:09 pm

    Hi Federico, I don’t have the problem. Perhaps you want to check if you have the file spmd2.c compiled to spmd2.mexglx correctly? or the path is added correctly? Wish you the best of luck!

  3. David
    November 2, 2011 at 11:58 pm

    Hello! when you say “Run MEX”…. what is mex?

    • November 7, 2011 at 12:52 am

      Hi David, sorry for the delay. I have been extremely busy finishing my thesis and working on fund-raising event. Basically when I say run mex, it means RUN the command mex in matlab
      >> mex somefile.c
      please refer to the URL: http://www.mathworks.com/help/techdoc/ref/mex.html
      Good luck!

  4. EricLin
    November 23, 2011 at 8:38 am

    HI!

    Thanks for your sharing!

    The information here is not only useful for you to memorize but useful for me to continue my research.

    But I can’t understand about the part :

    “(2) Run ‘gmake install’ from this directory to build everything. You
    should then probably put the lib/matlab directory in your MATLAB path……”

    The words ” Export path ” and ” make install ” seens like too complicated for me.

    If not too much trouble , could you please give it a more detail description ?

    Again , thanks for your patient and kindness.

    a confused student form Taiwan

    • November 23, 2011 at 12:42 pm

      Hi Eric,

      You caught me at a good time, Eric. I just passed defense yesterday, so I have some time to check my blog. Here are the answers to your questions:
      I assume that you are installing the superpixel toolbox on Ubuntu machine.
      PATH –> a command to add a path to the compiler environment.
      export PATH –> list all the paths included to the compiler environment. That’s because we want to make sure that the MATLAB path is included.
      I’m using Ubuntu, so I use “make install” instead of “gmake install”.
      The details of how to install it, please start reading on the post starting at the line saying
      “Now at the folder, student1@student1-desktop:~/MATLABcodes/superpixels/segbench$”

      You know, when I installed this toolbox first time, I also received helps from a Ubuntu-user friend. If you have one, please ask him/her to walk you through the process. He/she will know what to do exactly. Good luck!

  5. EricLin
    November 24, 2011 at 9:07 am

    Bot , thanks again.

    I finally knew why I can’t figure out the process here,

    The system I am using is not Linux (Ubuntu), but Windows XP.

    I have to say , it’s a pity that I can’t use the information here to perform superpixel code .

    But ,anyway,

    It’s still very nice of you to reply me in such a clear way.

    Thanks a lot, and I believe I will find out some methods to solve this problem.

  6. Mohammad
    September 19, 2012 at 2:14 am

    Hi ,
    Thanks for your sharing.

    I was trying to use Mori’s code however I got an strange fault on linux.
    Could you send me your opinion about this…..

    running PB
    [……..]
    [……..]
    [……..]
    [……..]
    pb took 1.30 minutes
    Ncutting…
    ————————————————————————
    Segmentation violation detected at Tue Sep 18 16:41:52 2012
    ————————————————————————

    Configuration:
    MATLAB Version: 7.5.0.338 (R2007b)
    MATLAB License: 146721
    Operating System: Linux 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64
    GNU C Library: 2.5 stable
    Window System: The X.Org Foundation (70101000), display :0.0
    Current Visual: 0×21 (class 4, depth 24)
    Processor ID: x86 Family 6 Model 12 Stepping 2, GenuineIntel
    Virtual Machine: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
    Default Charset: UTF-8

    Register State:
    rax = 0000000000000002 rbx = 00002aaaccfdf2f8
    rcx = 00002f22d6cc74a0 rdx = 00002aaaccb02d00
    rbp = 000000004212eca0 rsi = 0000008f00000090
    rdi = 0000013f0000013f rsp = 000000004212ea90
    r8 = 0000000000000000 r9 = 0000008f0000008f

  7. Mohammad
    September 19, 2012 at 4:58 am

    I have compiled it with windows, Matlab 2008a and it works.
    It seems the error is only for linux.

  1. February 4, 2012 at 4:10 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: