File Exchange

image thumbnail

Kernel graph cut image segmentation

version 1.0.0.0 (219 KB) by Ismail Ben Ayed
Kernel graph cut segmentation according to the formulation in M. Ben Salah et al., IEEE TIP, 2011.

15 Downloads

Updated 11 Oct 2012

View License

This code implements multi-region graph cut image segmentation according
to the kernel-mapping formulation in M. Ben Salah, A. Mitiche, and
I. Ben Ayed, Multiregion Image Segmentation by Parametric Kernel Graph
Cuts, IEEE Transactions on Image Processing, 20(2): 545-557 (2011).

The code uses Veksler, Boykov, Zabih and Kolmogorov’s implementation
of the Graph Cut algorithm. Written in C++, the graph cut algorithm comes
bundled with a MATLAB wrapper by Shai Bagon (Weizmann), which has to be downloaded from the following link (Matlab Wrapper for Graph Cuts):

http://www.wisdom.weizmann.ac.il/~bagon/matlab_code/GCmex1.9.tar.gz

The kernel-mapping part was implemented in MATLAB by M. Ben Salah (University of Alberta). If you use this code, please cite the papers mentioned in the
accompanying bib file (citations.bib).

The kernel-mapping formulation can handle various type of images, including
color photographs as well as data corrupted by a strong multiplicative
noise as in remote sensing synthetic aperture radar (SAR) or medical imaging
ultrasound. It is an efficient and flexible alternative to explicit modeling
of imaging noise using standard distributions (e.g., Gamma, Raleigh, Exponential,
Gaussian, Weibull, etc.).

Complete details on usage and compilation can be found in the enclosed
pdf file (Readme.pdf).

This code was tested on the following versions of MATLAB and C++:

MATLAB Version: 7.12.0.635 (R2011a) for 32-bit wrapper
Microsoft Visual C++ 2010 Express

Cite As

Ismail Ben Ayed (2020). Kernel graph cut image segmentation (https://www.mathworks.com/matlabcentral/fileexchange/38555-kernel-graph-cut-image-segmentation), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (38)

Tuan Nguyen

how to run it

Nathan Zhang

download from this link and compile_gc.m file works perfectly

https://github.com/shaibagon/GCMex

A terrific toolbox. Tested on my computer, Matlab 2017a, VC 2017 community.
Easy to use, two inputs required: 1. the number of regions (labels). 2. smoothness index.

approximately 3-5min: CORE i7, 16G ram, 720x960 pic, k = 6.

Naim

I'm getting the following error trying to compile the MEX files:

Error using mex
C:\graphcutstuff\graph.cpp: In member function 'void Graph::add_edge(Graph::node_id, Graph::node_id, Graph::captype, Graph::captype)':
C:\graphcutstuff\graph.cpp:89:21: error: cast from 'char*' to 'int' loses precision [-fpermissive]
if ((POINTER_CAST)ptr & 1) arc_for_block_first = (arc_for_block *) (ptr + 1);
......

Any idea what the problem might be?

Bimal Vinod

Am sorry , there was problem in the way i compiled mex files...Now it is fine, the code is working ..Thanks

Bimal Vinod

hi
I am getting error in mex , could any one help ? I am using mex for first time.But seems like the error comes from the cpp code. But am not sure ..pls help.error is as follows.
Error using mex

In member function 'void Graph::add_edge(Graph::node_id, Graph::node_id, Graph::captype,
Graph::captype)':

error: cast from 'char*' to 'int' loses precision [-fpermissive]
if ((POINTER_CAST)ptr & 1) arc_for_block_first = (arc_for_block *) (ptr + 1);

error: cast from 'Graph::arc_forward* {aka Graph::arc_forward_st*}' to 'int' loses
precision [-fpermissive]
#define IS_ODD(a) ((POINTER_CAST)(a) & 1)

error: cast from 'Graph::arc_reverse_st*' to 'int' loses precision [-fpermissive]
k = (POINTER_CAST) i -> first_in;

etc

Matlab crashes

Nina

klin

Only successfully to run it once.. Matlab crashes everytime when trying to run it.

David

In response to those who get a an error that says "Undefined function 'Graphcut' for...", the issue is that you have to use the MEX compiler first in order to use them. If I recall correctly, the readme file tells you how to do it.

David

I like it enough, but my copy of Matlab tends to crash often when I use it.

I tried to run this code but error comes while accessing mex file can you send me all files in .m extension?my e-mail adddress is ayeshaf1339@gmail.com

Hi everyone I tried to run the script on Matlab 2013 but getting an error
Undefined function 'GraphCut' for input arguments of type 'char'.

Error in Kernel_GraphCuts_Examples (line 105)
gch = GraphCut('open', Dc, Sc, Vc, Hc);

Please help

Hi, I tried to use this code but an error appears :
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: 'maxow.cpp' not found.

Zhiwei Zhai

Hi everyone,

Please, could you help me to run this script?

I've got this message:
Undefined function 'GraphCut' for input arguments of type 'char'.

Error in Kernel_GraphCuts_Examples (line 105)
gch = GraphCut('open', Dc, Sc, Vc, Hc);

What should I do?

I will highly appreciated any help.
My email is : swiwira2010@hotmail.fr

Nada Kadhim

muhammad

hi guyz i try to run this code in matlb according to the instrction given in the readme file but when ever i run the "mex -setup " command to convert the cpp file to max file this error occur
""""
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012a/win64.html

Please choose your compiler for building MEX-files:

Would you like mex to locate installed compilers [y]/n? y

No supported SDK or compiler was found on this computer.
For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012a/win64.html

Error using mex (line 206)
Unable to complete successfully.
""""'
need your kind support to sort out this problem

mawais069@gmail.com

muhammad

hi guyz i try to run this code in matlb according to the instrction given in the readme file but when ever i run the "mes -setup " command to convert the cpp file to max file this error occur
""""
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012a/win64.html

Please choose your compiler for building MEX-files:

Would you like mex to locate installed compilers [y]/n? y

No supported SDK or compiler was found on this computer.
For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012a/win64.html

Error using mex (line 206)
Unable to complete successfully.
""""'
need your kind support to sort out this problem

mawais069@gmail.com

Nada Kadhim

Hi everyone,

Please, could you help me to run this script?

I've got this message:
Undefined function 'GraphCut' for input arguments of type 'char'.

Error in Kernel_GraphCuts_Examples (line 105)
gch = GraphCut('open', Dc, Sc, Vc, Hc);

What should I do?

I will highly appreciated any help.
My email is : nada.flower@gmail.com

Zhiwei Zhai

Thank you for the cod. It works very well with 2D image, I plan to use it on the 3D images. Are you going to provide a version for 3D iamges? The graph-cut can work with 3D iamges and kernel function can also work on 3D images. So I think it is possible for 3D version.

there is a function error please email me the complete code please mail at ishdeep.singla@gmail.com

thanks for this code . but the function is not defined as gch = GraphCut('open', Dc, Sc, Vc, Hc)it gives error so please mail me if you have this function "prabhjotsinghkohli1990@gmail.com"

thanks for this code . but the function is not defined as gch = GraphCut('open', Dc, Sc, Vc, Hc)it gives error so please mail me if you have this function "prabhjotsinghkohli1990@gmail.com"

Fatma

Hi Ismail,

Thank You so much for the code.
I'm trying to use it for the segmentation of radiographic image of the femur (it is gray scale and the contrast is low).
I didn't get any efficient result. When I display the result LL or img, i obtain only zeros or ones (constant).
Can you please help me ?

Ben

It works well for 2D image. However, this code does not work for 3D image. Are you going to provide a version for 3D image segmentation?

-Ben

Amarjot

Hi, Thax for your code. Although i am getting this error in the graph-cut code. can you please help..

Undefined function 'GraphCutConstr' for input arguments of type
'single'.

Error in GraphCut>OpenGraph (line 367)
gch = GraphCutConstr(w, h, l, Dc, Sc, vC(:), hC(:));

Error in GraphCut (line 191)
gch = OpenGraph(varargin{:});

Error in Kernel_GraphCuts_Examples (line 105)
gch = GraphCut('open', Dc, Sc, Vc, Hc);

speedy

Hi Ismael,
thanks a lot for your code. However, it does not work for me so far. I used your example file and simply replaced the path of the brain image with my own greyscale .tif image (it is uint16 though while the example image is uint8). I get the following output:

Warning: Contour not rendered for constant ZData
> In contour>parseargs at 223
In contour at 79
In Kernel_GraphCuts_Examples at 252

and, in accordance with this, only one segmented region.

I randomly discovered this line in the example file (somewhere around line 130 in the original file):

if size(im, 1)==1 % Gray-level image

I might be wrong but shouldn't that read "if size(im, 3)==1"? If I change it to that and try again, I get an error message:

Error using GraphCut>OpenGraph (line 382)
Wrong size of Dc or Sc

Error in GraphCut (line 191)
gch = OpenGraph(varargin{:});

Error in Kernel_GraphCuts_Examples (line 110)
gch = GraphCut('open', Dc, Sc, Vc, Hc);

Do you have a quick idea why that is?

SH

Sepehr

Sepehr

Dear Ismael
Thanks for your email and feedback. I checked again now, and the link to download the rest of the code, works today. Thanks for your code.

Sepehr

Dear Sepehr:
The link works on my machine, and the code was tried successfully already by many people. Try to copy/paste the link in a new window (rather than clicking directly on the link). Alternatively, you can go to Shai Bagon's homepage: http://www.wisdom.weizmann.ac.il/~bagon/matlab.html
and click on "example" under section Matlab Wrapper for Graph Cuts.

As explained in details in the readme file and in the code description, this code requires additional graph cut source files (it is not incomplete). We cannot add these files to our submission because they are under a different type of license (and they are not our files).

Sepehr

The code is not complete, and the link does not work...

Med

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