0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 function demo3
0022 close all;
0023 fprintf('Welcome to SGWT demo #3\n');
0024
0025 imname='paques_attack.png';
0026 fprintf('loading image %s\n',imname);
0027 im = double( imread(imname) );
0028
0029 fprintf('Building mesh adjacency graph\n');
0030 A=sgwt_meshmat(size(im));
0031
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;
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
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;
0058 fprintf('\nsetting all coefficients to zero except wavelet scale %g\n',ks-1);
0059
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
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