reconSFpyr.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. % RES = reconSFpyr(PYR, INDICES, LEVS, BANDS, TWIDTH)
  2. %
  3. % Reconstruct image from its steerable pyramid representation, in the Fourier
  4. % domain, as created by buildSFpyr.
  5. %
  6. % PYR is a vector containing the N pyramid subbands, ordered from fine
  7. % to coarse. INDICES is an Nx2 matrix containing the sizes of
  8. % each subband. This is compatible with the MatLab Wavelet toolbox.
  9. %
  10. % LEVS (optional) should be a list of levels to include, or the string
  11. % 'all' (default). 0 corresonds to the residual highpass subband.
  12. % 1 corresponds to the finest oriented scale. The lowpass band
  13. % corresponds to number spyrHt(INDICES)+1.
  14. %
  15. % BANDS (optional) should be a list of bands to include, or the string
  16. % 'all' (default). 1 = vertical, rest proceeding anti-clockwise.
  17. %
  18. % TWIDTH is the width of the transition region of the radial lowpass
  19. % function, in octaves (default = 1, which gives a raised cosine for
  20. % the bandpass filters).
  21. %%% MODIFIED VERSION, 7/04, uses different lookup table for radial frequency!
  22. % Eero Simoncelli, 5/97.
  23. function res = reconSFpyr(pyr, pind, levs, bands, twidth)
  24. %%------------------------------------------------------------
  25. %% DEFAULTS:
  26. if (exist('levs') ~= 1)
  27. levs = 'all';
  28. end
  29. if (exist('bands') ~= 1)
  30. bands = 'all';
  31. end
  32. if (exist('twidth') ~= 1)
  33. twidth = 1;
  34. elseif (twidth <= 0)
  35. fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n');
  36. twidth = 1;
  37. end
  38. %%------------------------------------------------------------
  39. nbands = spyrNumBands(pind);
  40. maxLev = 1+spyrHt(pind);
  41. if strcmp(levs,'all')
  42. levs = [0:maxLev]';
  43. else
  44. if (any(levs > maxLev) | any(levs < 0))
  45. error(sprintf('Level numbers must be in the range [0, %d].', maxLev));
  46. end
  47. levs = levs(:);
  48. end
  49. if strcmp(bands,'all')
  50. bands = [1:nbands]';
  51. else
  52. if (any(bands < 1) | any(bands > nbands))
  53. error(sprintf('Band numbers must be in the range [1,3].', nbands));
  54. end
  55. bands = bands(:);
  56. end
  57. %----------------------------------------------------------------------
  58. dims = pind(1,:);
  59. ctr = ceil((dims+0.5)/2);
  60. [xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ...
  61. ([1:dims(1)]-ctr(1))./(dims(1)/2) );
  62. angle = atan2(yramp,xramp);
  63. log_rad = sqrt(xramp.^2 + yramp.^2);
  64. log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1);
  65. log_rad = log2(log_rad);
  66. %% Radial transition function (a raised cosine in log-frequency):
  67. [Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]);
  68. Yrcos = sqrt(Yrcos);
  69. YIrcos = sqrt(abs(1.0 - Yrcos.^2));
  70. if (size(pind,1) == 2)
  71. if (any(levs==1))
  72. resdft = fftshift(fft2(pyrBand(pyr,pind,2)));
  73. else
  74. resdft = zeros(pind(2,:));
  75. end
  76. else
  77. resdft = reconSFpyrLevs(pyr(1+prod(pind(1,:)):size(pyr,1)), ...
  78. pind(2:size(pind,1),:), ...
  79. log_rad, Xrcos, Yrcos, angle, nbands, levs, bands);
  80. end
  81. lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
  82. resdft = resdft .* lo0mask;
  83. %% residual highpass subband
  84. if any(levs == 0)
  85. hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
  86. hidft = fftshift(fft2(subMtx(pyr, pind(1,:))));
  87. resdft = resdft + hidft .* hi0mask;
  88. end
  89. res = real(ifft2(ifftshift(resdft)));