Matlab code download and implementation of Ncut algorithm normal operation on MATLAB

Source: Internet
Author: User
Tags sin sprintf

Here I use the platform is:win7 (64bit) +matlab2014a (64bit)

The full name of the ncut algorithm should be:Multiscale normalized Cut image segmentation, is the image segmentation algorithm. Can be said to be my current graduate career use of the segmentation effect is a more ideal image segmentation algorithm,

Code for: http://timotheecour.com/software/ncut_multiscale/ncut_multiscale.html

After entering the interface, you will see the area shown below, where we download the latest ncut_multiscale_1_6.zip.

After the download is complete, we unzip the compressed file and we can see that there is a. m file in the extracted file, and a. cpp file, as shown in (section).

Because the. cpp file needs to be compiled to be called, so the next most important compile link, compiled we need to create the COMPLIEDIR_SIMPLE.M file in the extracted folder, the code is as follows:

function Compiledir_simple (cdir);ifnargin<1Cdir=Pwd;endfiles= Dir (FullFile (Cdir,'*.cpp')); Olddir=PWD;CD (cdir); forj=1: Length (Files)Try% cm = sprintf ('Mex%s', Files (j). Name); CM= sprintf ('Mex-largearraydims%s', Files (j). Name);        Disp (cm);    eval (cm); Catchdisp (LastErr); Disp ('IGNORE If the file is a C + + file which is not a Mex file (ie without a mexfunction inside)'); ENDENDCD (olddir);

After the creation, we can click the Run button in MATLAB to compile the CPP file, after compiling you will find that the folder is more than the suffix. mexw64 file, where w represents the Windows system, 64 for the system is 64-bit.

Next we test whether the ncut algorithm can be called, ncut the invocation of the algorithm, we just call the NCUT_MULTISCALE.M file on the line (see below). That is to call this [classes,x,lambda,xr,w,c,timing] = Ncut_multiscale (image,nsegs,options);

Here I give a test code I use, first in the current folder Ncut code to create a TEST.M file, of course, the file name you can go, the code is as follows:

Image = Imread ('v48752.jpg'); Ncut=Ten; IM=Image;n=ncut;region= Ncut_multiscale (Image,Ten); [X,y,c]=size (image); IM1=Region ; form=1: Ncut forI=1: x forj=1: YifIM1 (i,j) = =m IM (i,j,1)=255*abs (Sin (255-m* -)); Im (I,j,2)=255*abs (cos (m)); Im (I,j,3)=255*abs (Sin (m* -)); End Endendendfigure;imshow (IM)

The image here called is the ncut algorithm extracted from the file after the image, which you can find in the file.

If you are using a version of MATLAB version 2013a and above, then the operation should be reported that the Cholinc function is not found, this is because the Cholinc function is deprecated after the MATLAB2012 version, 2013a below the version to this step should be able to run successfully. For the encountered Cholinc function error problem can be replaced by the Ichol function, specifically how to replace, here is a code to replace the example:

R = Cholinc (C, ' 0 '); Replace with R = Ichol (c,struct (' type ', ' ICT ', ' Droptol ', 0, ' shape ', ' upper ')); (To find out why this is replaced, you can see this link: http://stackoverflow.com/ Questions/12895228/ichol-as-cholinc-replacement-nonpositive-pivot)

The other two substitutions in the code are as follows:

Solve this problem, we can run the downloaded ncut algorithm normally. Finally run the test.m file as shown in the results:

Input:

Output:

This completes the normal operation of the Ncut code.

Here to add, ah, ncut algorithm can also be used for clustering, specific code download and bug fix can see the following links:

Http://www.cnblogs.com/Azhu/p/4145166.html The author gives a detailed explanation.

Matlab code download and implementation of Ncut algorithm normal operation on MATLAB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.