reconSpyr.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. % RES = reconSpyr(PYR, INDICES, FILTFILE, EDGES, LEVS, BANDS)
  2. %
  3. % Reconstruct image from its steerable pyramid representation, as created
  4. % by buildSpyr.
  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. % FILTFILE (optional) should be a string referring to an m-file that returns
  11. % the rfilters. examples: sp0Filters, sp1Filters, sp3Filters
  12. % (default = 'sp1Filters').
  13. % EDGES specifies edge-handling, and defaults to 'reflect1' (see
  14. % corrDn).
  15. %
  16. % LEVS (optional) should be a list of levels to include, or the string
  17. % 'all' (default). 0 corresonds to the residual highpass subband.
  18. % 1 corresponds to the finest oriented scale. The lowpass band
  19. % corresponds to number spyrHt(INDICES)+1.
  20. %
  21. % BANDS (optional) should be a list of bands to include, or the string
  22. % 'all' (default). 1 = vertical, rest proceeding anti-clockwise.
  23. % Eero Simoncelli, 6/96.
  24. function res = reconSpyr(pyr, pind, filtfile, edges, levs, bands)
  25. %%------------------------------------------------------------
  26. %% DEFAULTS:
  27. % Deterimine whether a MEX version of upConv is available
  28. is_mex = true;
  29. finfo = functions( @upConv );
  30. if( strcmp( finfo.file((end-2):end), '.m') )
  31. is_mex = false;
  32. end
  33. if (exist('filtfile') ~= 1)
  34. filtfile = 'sp1Filters';
  35. end
  36. if (exist('edges') ~= 1)
  37. edges= 'reflect1';
  38. end
  39. if (exist('levs') ~= 1)
  40. levs = 'all';
  41. end
  42. if (exist('bands') ~= 1)
  43. bands = 'all';
  44. end
  45. %%------------------------------------------------------------
  46. if (isstr(filtfile) & (exist(filtfile) == 2))
  47. [lo0filt,hi0filt,lofilt,bfilts,steermtx,harmonics] = eval(filtfile);
  48. nbands = spyrNumBands(pind);
  49. if ((nbands > 0) & (size(bfilts,2) ~= nbands))
  50. error('Number of pyramid bands is inconsistent with filter file');
  51. end
  52. else
  53. error('filtfile argument must be the name of an M-file containing SPYR filters.');
  54. end
  55. maxLev = 1+spyrHt(pind);
  56. if strcmp(levs,'all')
  57. levs = [0:maxLev]';
  58. else
  59. if (any(levs > maxLev) | any(levs < 0))
  60. error(sprintf('Level numbers must be in the range [0, %d].', maxLev));
  61. end
  62. levs = levs(:);
  63. end
  64. if strcmp(bands,'all')
  65. bands = [1:nbands]';
  66. else
  67. if (any(bands < 1) | any(bands > nbands))
  68. error(sprintf('Band numbers must be in the range [1,3].', nbands));
  69. end
  70. bands = bands(:);
  71. end
  72. if (spyrHt(pind) == 0)
  73. if (any(levs==1))
  74. res1 = pyrBand(pyr,pind,2);
  75. else
  76. res1 = zeros(pind(2,:));
  77. end
  78. else
  79. res1 = reconSpyrLevs(pyr(1+prod(pind(1,:)):size(pyr,1)), ...
  80. pind(2:size(pind,1),:), ...
  81. lofilt, bfilts, edges, levs, bands);
  82. end
  83. res = upConv(res1, lo0filt, edges);
  84. %% residual highpass subband
  85. if any(levs == 0)
  86. if( is_mex )
  87. upConv( subMtx(pyr, pind(1,:)), hi0filt, edges, [1 1], [1 1], size(res), res);
  88. else
  89. res = upConv( subMtx(pyr, pind(1,:)), hi0filt, edges, [1 1], [1 1], size(res), res);
  90. end
  91. end