1 function demoNcutImage;
\r
5 % also initialize matlab paths to subfolders
\r
6 % Timothee Cour, Stella Yu, Jianbo Shi, 2004.
\r
8 disp('Ncut Image Segmentation demo');
\r
10 %% read image, change color image to brightness image, resize to 160x160
\r
11 I = imread_ncut('jpg_images/3.jpg',160,160);
\r
13 %% display the image
\r
14 figure(1);clf; imagesc(I);colormap(gray);axis off;
\r
15 disp('This is the input image to segment, press Enter to continue...');
\r
18 %% compute the edges imageEdges, the similarity matrix W based on
\r
19 %% Intervening Contours, the Ncut eigenvectors and discrete segmentation
\r
21 disp('computing Ncut eigenvectors ...');
\r
23 [SegLabel,NcutDiscrete,NcutEigenvectors,NcutEigenvalues,W,imageEdges]= NcutImage(I,nbSegments);
\r
24 disp(['The computation took ' num2str(toc) ' seconds on the ' num2str(size(I,1)) 'x' num2str(size(I,2)) ' image']);
\r
27 %% display the edges
\r
28 figure(2);clf; imagesc(imageEdges); axis off
\r
29 disp('This is the edges computed, press Enter to continue...');
\r
32 %% display the segmentation
\r
34 bw = edge(SegLabel,0.01);
\r
35 J1=showmask(I,imdilate(bw,ones(2,2))); imagesc(J1);axis off
\r
36 disp('This is the segmentation, press Enter to continue...');
\r
39 %% display Ncut eigenvectors
\r
40 figure(4);clf;set(gcf,'Position',[100,500,200*(nbSegments+1),200]);
\r
41 [nr,nc,nb] = size(I);
\r
43 subplot(1,nbSegments,i);
\r
44 imagesc(reshape(NcutEigenvectors(:,i) , nr,nc));axis('image');axis off;
\r
46 disp('This is the Ncut eigenvectors...');
\r
47 disp('The demo is finished.');
\r