/code/3D image registration/dtcwt_toolbox4_3/shift_test_2D.m

http://sparse-mri-reconstruction.googlecode.com/ · MATLAB · 111 lines · 71 code · 22 blank · 18 comment · 4 complexity · 0869107c16f483ab11eaec20c2458070 MD5 · raw file

  1. % shift_test_2D.m
  2. %
  3. % M-file to perform a 4-level wavelet transform on a circle using Q-shift
  4. % dual wavelet tree and DWT, and to compare shift invariance properties.
  5. %
  6. % Nick Kingsbury, Cambridge University, May 2002.
  7. clear all
  8. close all
  9. % Draw a circular disc.
  10. x = round((drawcirc(64,1,0,0,256) - 0.5) * 170);
  11. setfig(1);
  12. colormap(gray(256))
  13. image(min(max(x+128,1),256));
  14. set(gca,'position',[0.1 0.25 .25 .5]);
  15. axis('off');
  16. axis('image');
  17. % draw(xx);
  18. title('Input (256 x 256)','FontSize',14); drawnow
  19. settitle('Input');
  20. drawnow
  21. % print -depsc circ1.eps
  22. % Do 4 levels of CWT.
  23. [Yl,Yh] = dtwavexfm2(x,4,'near_sym_b','qshift_b');
  24. % Loop to reconstruct output from coefs at each level in turn.
  25. % Starts with the finest level.
  26. titl = ['1st';'2nd';'3rd';'4th';'Low'];
  27. yy = zeros(size(x) .* [2 3]);
  28. yt1 = 1:size(x,1); yt2 = 1:size(x,2);
  29. for mlev = 1:5,
  30. mask = zeros(6,5);
  31. mask(:,mlev) = 1;
  32. z = dtwaveifm2(Yl*mask(1,5),Yh,'near_sym_b','qshift_b',mask);
  33. figure;draw(z);drawnow
  34. settitle([titl(mlev,:) ' level DTCWT subbands']);
  35. yy(yt1,yt2) = z;
  36. yt2 = yt2 + size(x,2)/2;
  37. end
  38. % disp('Press a key ...')
  39. % pause
  40. % Now do same with DWT.
  41. % Do 4 levels of Real DWT using 'antonini' (9,7)-tap filters.
  42. [Yl,Yh] = wavexfm2(x,4,'antonini');
  43. yt1 = [1:size(x,1)] + size(x,1); yt2 = 1:size(x,2);
  44. for mlev = 1:5,
  45. mask = zeros(3,5);
  46. mask(:,mlev) = 1;
  47. z = waveifm2(Yl*mask(1,5),Yh,'antonini',mask);
  48. figure;draw(z);drawnow
  49. settitle([titl(mlev,:) ' level DWT subbands']);
  50. yy(yt1,yt2) = z;
  51. yt2 = yt2 + size(x,2)/2;
  52. end
  53. figure;
  54. setfig(gcf);
  55. colormap(gray(256))
  56. image(min(max(yy+128,1),256));
  57. set(gca,'position',[0.1 0.1 .8 .8]);
  58. axis('off');
  59. axis('image');
  60. hold on
  61. plot(128*[[1;1]*[1:4] [0;6]]+1,128*[[0;4]*[1 1 1 1] [2;2]]+1,'-k');
  62. hold off
  63. title('Components of reconstructed ''disc'' images','FontSize',14);
  64. text(-0.01*size(yy,2),0.25*size(yy,1),'DT CWT','horiz','r');
  65. text(0.02*size(yy,2),1.02*size(yy,1),'wavelets:','horiz','r','vert','t');
  66. text(-0.01*size(yy,2),0.75*size(yy,1),'DWT','horiz','r');
  67. for k=1:4, text(k*128-63,size(yy,1)*1.02,sprintf('level %d',k),'FontSize',14,'horiz','c','vert','t'); end
  68. text(5*128+1,size(yy,1)*1.02,'level 4 scaling fn.','FontSize',14,'horiz','c','vert','t');
  69. drawnow
  70. % print -deps circrecq.eps
  71. disp('Press a key to see perfect reconstruction property ...')
  72. pause
  73. % Accumulate the images from lowband upwards to show perfect reconstruction.
  74. sy = size(x,2)/2;
  75. for mlev = 4:-1:1,
  76. yt2 = [1:sy] + (mlev-1)*sy;
  77. yy(:,yt2) = yy(:,yt2) + yy(:,yt2+sy);
  78. end
  79. figure;
  80. setfig(gcf);
  81. colormap(gray(256))
  82. image(min(max(yy+128,1),256));
  83. set(gca,'position',[0.1 0.1 .8 .8]);
  84. axis('off');
  85. axis('image');
  86. title('Accumulated reconstructions from each level of DT CWT ','FontSize',14);
  87. text(size(yy,2)*0.5,size(yy,1)*1.02,'Accumulated reconstructions from each level of DWT ','FontSize',14,'hor','c','vert','t');
  88. drawnow
  89. return