buildSpyr.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. % [PYR, INDICES, STEERMTX, HARMONICS] = buildSpyr(IM, HEIGHT, FILTFILE, EDGES)
  2. %
  3. % Construct a steerable pyramid on matrix IM. Convolutions are
  4. % done with spatial filters.
  5. %
  6. % HEIGHT (optional) specifies the number of pyramid levels to build. Default
  7. % is maxPyrHt(size(IM),size(FILT)).
  8. % You can also specify 'auto' to use this value.
  9. %
  10. % FILTFILE (optional) should be a string referring to an m-file that
  11. % returns the rfilters. (examples: 'sp0Filters', 'sp1Filters',
  12. % 'sp3Filters','sp5Filters'. default = 'sp1Filters'). EDGES specifies
  13. % edge-handling, and defaults to 'reflect1' (see corrDn).
  14. %
  15. % PYR is a vector containing the N pyramid subbands, ordered from fine
  16. % to coarse. INDICES is an Nx2 matrix containing the sizes of
  17. % each subband. This is compatible with the MatLab Wavelet toolbox.
  18. % See the function STEER for a description of STEERMTX and HARMONICS.
  19. % Eero Simoncelli, 6/96.
  20. % See http://www.cis.upenn.edu/~eero/steerpyr.html for more
  21. % information about the Steerable Pyramid image decomposition.
  22. function [pyr,pind,steermtx,harmonics] = buildSpyr(im, ht, filtfile, edges)
  23. %-----------------------------------------------------------------
  24. %% DEFAULTS:
  25. if (exist('filtfile') ~= 1)
  26. filtfile = 'sp1Filters';
  27. end
  28. if (exist('edges') ~= 1)
  29. edges= 'reflect1';
  30. end
  31. if (isstr(filtfile) & (exist(filtfile) == 2))
  32. [lo0filt,hi0filt,lofilt,bfilts,steermtx,harmonics] = eval(filtfile);
  33. else
  34. fprintf(1,'\nUse buildSFpyr for pyramids with arbitrary numbers of orientation bands.\n');
  35. error('FILTFILE argument must be the name of an M-file containing SPYR filters.');
  36. end
  37. max_ht = maxPyrHt(size(im), size(lofilt,1));
  38. if ( (exist('ht') ~= 1) | (ht == 'auto') )
  39. ht = max_ht;
  40. else
  41. if (ht > max_ht)
  42. error(sprintf('Cannot build pyramid higher than %d levels.',max_ht));
  43. end
  44. end
  45. %-----------------------------------------------------------------
  46. hi0 = corrDn(im, hi0filt, edges);
  47. lo0 = corrDn(im, lo0filt, edges);
  48. [pyr,pind] = buildSpyrLevs(lo0, ht, lofilt, bfilts, edges);
  49. pyr = [hi0(:) ; pyr];
  50. pind = [size(hi0); pind];