View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Foreground segmentation

3.7 | 10 ratings Rate this file 39 Downloads (last 30 days) File Size: 639 KB File ID: #6860 Version: 1.0
image thumbnail

Foreground segmentation


Nicholas Howe (view profile)


04 Feb 2005 (Updated )

Uses graph cuts to segment foreground objects from a static background in video.

| Watch this File

File Information

This package contains m-files for the segmentation of a moving foreground from video with a static background, using graph cuts to achieve a clean result.

For more details and an accompanying paper please see

MATLAB release MATLAB 7.0.1 (R14SP1)
Other requirements Indeo 5 codec for sample video.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
04 Aug 2016 chfakht chfakht

Any alternatives to Indeo5 ? since it's not supported in windows 7 64 bits.

06 Dec 2014 Adnan

Adnan (view profile)

Not working.. error in opening SampleVideo.avi. I tried (.avi) video from own dataset and got error
Undefined function 'gcut' for input arguments of type 'double'.

Error in graphLabel (line 16)
cut = gcut([zeros(2),C;C',P],[1 2]);

26 Sep 2014 Mohammad Mahdi Derakhshani

Hello Dears,
when I executed this script in Maltab I received this error,
Undefined function 'gcut' for input arguments
of type 'double'.
Error in graphLabel (line 16)
cut = gcut([zeros(2),C;C',P],[1 2]);
Error in extractForeground (line 113)
label =

Error in RUNME (line 29)
fg = extractForeground(frames);

So how can I solve it? Please help me it's so crucial for me to settle that!!

Comment only
07 May 2014 Turgay Senlet

The problem comes from the places where original code converts int's to pointers. In 32-bit machine this is okay, but with 64-bit, you need to use a 64-bit type instead of int. In this case, if you read the error in detail, it tells you that mwIndex (a 64-bit pointer of type unsigned long *) is being assigned to an int. If you go to that line you see ir = mxGetIr(prhs[0]); Find where ir is defined (line 127: int *ir, *jc;) and change its type to a unsigned long *. unsigned long *ir, *jc; And repeat a similar procedure for this kind of errors (occurs 5-6 times, including the ones in pixCon.cpp).
I did this and I was able to compile with large arrays, but my Matlab crashes when running the code. Good luck.

Comment only
07 Aug 2013 Kiwon Yun

I also have the same problem to compile the 'gcut.cpp' file by using 'mex' in a 64-bits machine. Does somebody solve this?

Comment only
05 Feb 2013 Cedric

Cedric (view profile)

I have this problem while doing the mex file (linux 64-bits version):

mex gcut.cpp -largeArrayDims

Warning: You are using gcc version "4.6.3-1ubuntu5)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:

gcut.cpp: In function ‘void matlabParse(int, const mxArray**, long int*, long int*, node**, arc**, long int**, node**, node**, long int*)’:
gcut.cpp:144:25: error: cannot convert ‘mwIndex* {aka long unsigned int*}’ to ‘int*’ in assignment
gcut.cpp:145:25: error: cannot convert ‘mwIndex* {aka long unsigned int*}’ to ‘int*’ in assignment

mex: compile of ' "gcut.cpp"' failed.

Comment only
04 May 2011 zhang

zhang (view profile)

thank you

Comment only
04 May 2011 zhang

zhang (view profile)

thank you!

Comment only
25 Mar 2009 Sean Connery

That`s exactly what I need now.Thank you so much~!

09 Sep 2008 saidi lotfi

23 May 2007 Krishna Sridhar

Really cool code.. I dont have much of a vision expertise and I wanted the foreground images..
This code works with such ease.. Just remember to do mex gcut.cpp when u copy into ur machine..

11 Apr 2006 Piyorot Khongchuay


07 Mar 2006 Alex Denone

17 Nov 2005 anand karemola

This is the best one for caputuring image,i wan use this code for my project.Could you please help for getting the graph cut images of different frames.I will appreciate if you could help me out.

29 Jun 2005 Ayesha Malik

Can you convert this piece of code for foreground segmentation on a live video?? I would certainly appreciate if you help me out in doing so.

16 Jun 2005 Kamran Iqbal

10 Feb 2005 MO Ahmed

Thank you

Comment only

Contact us