Home > sgwt_toolbox > demo > sgwt_demo3.m

sgwt_demo3

PURPOSE ^

sgwt_demo3 : Image decomposition with SGWT wavelets based on local adjacency.

SYNOPSIS ^

function sgwt_demo3

DESCRIPTION ^

 sgwt_demo3 : Image decomposition with SGWT wavelets based on local adjacency.

 This demo builds the SGWT transform on a graph representing 
 adjacency on a pixel mesh with 4-nearest neighbor connectivity.
 This demonstrates inverse on problem with large dimension.

 The demo loads an image file and decomposes the image with the SGWT,
 showing the coefficients as images at each scale. The demo does not show
 the individual wavelets (this could be done by replacing the input 
 image by a "delta image" with a single unit nonzero pixel) .

 The inverse is then computed, from the original coefficients as well as 
 from a modified set of coefficients where only coefficients at one
 scale are preserved. This shows that the SGWT can generate a
 multiresolution decomposition for images. We don't claim that this
 particular local-adjacency based transform is better for image
 processing than other available wavelet image decompositions, but it
 demonstrates the flexibility of the SGWT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % sgwt_demo3 : Image decomposition with SGWT wavelets based on local adjacency.
0002 %
0003 % This demo builds the SGWT transform on a graph representing
0004 % adjacency on a pixel mesh with 4-nearest neighbor connectivity.
0005 % This demonstrates inverse on problem with large dimension.
0006 %
0007 % The demo loads an image file and decomposes the image with the SGWT,
0008 % showing the coefficients as images at each scale. The demo does not show
0009 % the individual wavelets (this could be done by replacing the input
0010 % image by a "delta image" with a single unit nonzero pixel) .
0011 %
0012 % The inverse is then computed, from the original coefficients as well as
0013 % from a modified set of coefficients where only coefficients at one
0014 % scale are preserved. This shows that the SGWT can generate a
0015 % multiresolution decomposition for images. We don't claim that this
0016 % particular local-adjacency based transform is better for image
0017 % processing than other available wavelet image decompositions, but it
0018 % demonstrates the flexibility of the SGWT.
0019 
0020 % This file is part of the SGWT toolbox (Spectral Graph Wavelet Transform toolbox)
0021 % Copyright (C) 2010, David K. Hammond.
0022 %
0023 % The SGWT toolbox is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % The SGWT toolbox is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with the SGWT toolbox.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 function sgwt_demo3
0037 close all;
0038 fprintf('Welcome to SGWT demo #3\n');
0039 % load image
0040 imname='paques_attack.png';
0041 fprintf('loading image %s\n',imname);
0042 im = double( imread(imname) );
0043 % build mesh adjacency graph
0044 fprintf('Building mesh adjacency graph\n');
0045 A=sgwt_meshmat(size(im));
0046 % transform
0047 fprintf('Calculating graph Laplacian\n');
0048 L=sgwt_laplacian(A);
0049 fprintf('Measuring largest eigenvalue, lmax = ');
0050 lmax=sgwt_rough_lmax(L);
0051 arange=[0,lmax];
0052 fprintf('%g\n',lmax);
0053 
0054 Nscales=5;
0055 fprintf('Designing transform in spectral domain\n');
0056 [g,gp,t]=sgwt_filter_design(lmax,Nscales);
0057 
0058 m=25; % order of polynomial approximation
0059 fprintf('Computing Chebyshev polynomials of order %g for fast transform \n',m);
0060 for k=1:numel(g)
0061     c{k}=sgwt_cheby_coeff(g{k},m,m+1,arange);
0062 end
0063 
0064 fprintf('Computing forward transform\n');
0065 wpall=sgwt_cheby_op(im(:),L,c,arange);
0066 
0067 % invert with all subbands
0068 fprintf('Computing inverse transform with all coefficients\n');
0069 imr1=sgwt_inverse(wpall,L,c,arange);
0070 imr1=reshape(imr1,size(im));
0071 
0072 ks=3; % scale at which to keep coefficients, set all others to zero.
0073 fprintf('\nsetting all coefficients to zero except wavelet scale %g\n',ks-1);
0074 % invert with only one scale
0075 for k=1:numel(wpall)
0076     wpall2{k}=zeros(size(wpall{k}));
0077 end
0078 wpall2{ks}=wpall{ks};
0079 fprintf('Computing inverse transform with coefficients from wavelet scale %g only\n',ks-1);
0080 imr2=sgwt_inverse(wpall2,L,c,arange);
0081 imr2=reshape(imr2,size(im));
0082 
0083 %% display results
0084 figure(1)
0085 set(gcf,'position',[ 5   730   350   350]);
0086 sgwt_show_im(im)
0087 title('original image');
0088 set(gcf,'menubar','none')
0089 figure(2)
0090 set(gcf,'position',[365 730 350 350]);
0091 sgwt_show_im(imr1)
0092 title('reconstuction from all coefficients');
0093 set(gcf,'menubar','none')
0094 
0095 figure(3)
0096 set(gcf,'position',[725 730 350 350]);
0097 sgwt_show_im(imr2);
0098 title(sprintf('reconstruction only from wavelets at scale %g',ks-1));
0099 set(gcf,'menubar','none')
0100 
0101 figure(4)
0102 set(gcf,'position',[0 0 1150 700]);
0103 set(gcf,'menubar','none')
0104 for k=1:Nscales+1
0105     subplot(2,3,k);
0106     sgwt_show_im(reshape(wpall{k},size(im)));
0107     if k==1
0108         title('Scaling function coefficients');
0109     else
0110         title(sprintf('Wavelet coefficients at scale %g',k-1));
0111     end
0112 end

Generated on Tue 04-May-2010 16:00:20 by m2html © 2003