%Script used to generate Kaniza segmentation figure %2/2/03 - Leo Grady %Load image img=im2double(imread('./kaniza.bmp')); %Normalize image [x,y,dummy]=size(img); img2=img-min(min(img)); img2=img2./max(max(img2)); %Generate graph setSize=x*y; [points,edges]=lattice(x,y); A=adjacency(edges); %Remove inducers inducers=find(img<.9); index=1:(x*y); index(inducers)=[]; points=points(index,:); A=A(index,index); edges=adjtoedges(A); %Display structure figure %Flip points to compensate for MATLAB image reverse indexing dispPoints=[points(:,1),max(points(:,2))-points(:,2)]; gplot(A,dispPoints,'k'); axis tight axis equal axis off %------------------------------------------------------------------------- %Partition, grounded in the corner ground=920; %Set corner ground %ground=100; [part1,part2,constant,xFunction]=partitiongraph(A,0,0,0,index(ground)); %Markup partition imgMasks=zeros(x,y); imgMasks(index(part1))=1; %Outline segments [fx,fy]=gradient(imgMasks); xcont=find(fx); ycont=find(fy); segOutline=ones(x,y); segOutline(xcont)=0; segOutline(ycont)=0; imgMarkup=img2(:,:,1); imgMarkup(xcont)=1; imgMarkup(ycont)=1; imgTmp1=img2(:,:,1); imgTmp1(xcont)=0; imgTmp1(ycont)=0; imgMarkup(:,:,2)=imgTmp1; imgMarkup(:,:,3)=imgTmp1; figure imagesc(imgMarkup); hold on offset=points(index(ground),:); plot(offset(1),offset(2),'rx','MarkerSize',12,'LineWidth',5); axis tight axis off axis equal hold off %------------------------------------------------------------------------- %Partition, grounded in the center ground=5473; %Set center ground %Perform partitioning [part1,part2,constant,xFunction]=partitiongraph(A,0,0,0,index(ground)); %Markup partition imgMasks=zeros(x,y); imgMasks(index(part1))=1; %Outline segments [fx,fy]=gradient(imgMasks); xcont=find(fx); ycont=find(fy); segOutline=ones(x,y); segOutline(xcont)=0; segOutline(ycont)=0; imgMarkup=img2(:,:,1); imgMarkup(xcont)=1; imgMarkup(ycont)=1; imgTmp1=img2(:,:,1); imgTmp1(xcont)=0; imgTmp1(ycont)=0; imgMarkup(:,:,2)=imgTmp1; imgMarkup(:,:,3)=imgTmp1; figure imagesc(imgMarkup); hold on offset=points(index(ground),:); plot(offset(1),offset(2),'rx','MarkerSize',12,'LineWidth',5); axis tight axis off axis equal hold off