Home > sgwt_toolbox > demo > demo3.m

demo3

PURPOSE ^

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

SYNOPSIS ^

function demo3

DESCRIPTION ^

 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 % 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 
0021 function demo3
0022 close all;
0023 fprintf('Welcome to SGWT demo #3\n');
0024 % load image
0025 imname='paques_attack.png';
0026 fprintf('loading image %s\n',imname);
0027 im = double( imread(imname) );
0028 % build mesh adjacency graph
0029 fprintf('Building mesh adjacency graph\n');
0030 A=sgwt_meshmat(size(im));
0031 % transform
0032 fprintf('Calculating graph Laplacian\n');
0033 L=sgwt_laplacian(A);
0034 fprintf('Measuring largest eigenvalue, lmax = ');
0035 lmax=sgwt_rough_lmax(L);
0036 arange=[0,lmax];
0037 fprintf('%g\n',lmax);
0038 
0039 Nscales=5;
0040 fprintf('Designing transform in spectral domain\n');
0041 [g,gp,t]=sgwt_filter_design(lmax,Nscales);
0042 
0043 m=25; % order of polynomial approximation
0044 fprintf('Computing Chebyshev polynomials of order %g for fast transform \n',m);
0045 for k=1:numel(g)
0046     c{k}=sgwt_cheby_coeff(g{k},m,m+1,arange);
0047 end
0048 
0049 fprintf('Computing forward transform\n');
0050 wpall=sgwt_cheby_op(im(:),L,c,arange);
0051 
0052 % invert with all subbands
0053 fprintf('Computing inverse transform with all coefficients\n');
0054 imr1=sgwt_inverse(wpall,L,c,arange);
0055 imr1=reshape(imr1,size(im));
0056 
0057 ks=3; % scale at which to keep coefficients, set all others to zero.
0058 fprintf('\nsetting all coefficients to zero except wavelet scale %g\n',ks-1);
0059 % invert with only one scale
0060 for k=1:numel(wpall)
0061     wpall2{k}=zeros(size(wpall{k}));
0062 end
0063 wpall2{ks}=wpall{ks};
0064 fprintf('Computing inverse transform with coefficients from wavelet scale %g only\n',ks-1);
0065 imr2=sgwt_inverse(wpall2,L,c,arange);
0066 imr2=reshape(imr2,size(im));
0067 
0068 %% display results
0069 figure(1)
0070 set(gcf,'position',[ 5   730   350   350]);
0071 sgwt_show_im(im)
0072 title('original image');
0073 set(gcf,'menubar','none')
0074 figure(2)
0075 set(gcf,'position',[365 730 350 350]);
0076 sgwt_show_im(imr1)
0077 title('reconstuction from all coefficients');
0078 set(gcf,'menubar','none')
0079 
0080 figure(3)
0081 set(gcf,'position',[725 730 350 350]);
0082 sgwt_show_im(imr2);
0083 title(sprintf('reconstruction only from wavelets at scale %g',ks-1));
0084 set(gcf,'menubar','none')
0085 
0086 figure(4)
0087 set(gcf,'position',[0 0 1150 700]);
0088 set(gcf,'menubar','none')
0089 for k=1:Nscales+1
0090     subplot(2,3,k);
0091     sgwt_show_im(reshape(wpall{k},size(im)));
0092     if k==1
0093         title('Scaling function coefficients');
0094     else
0095         title(sprintf('Wavelet coefficients at scale %g',k-1));
0096     end
0097 end

Generated on Fri 30-Apr-2010 17:49:57 by m2html © 2003