reconLpyr.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. % RES = reconLpyr(PYR, INDICES, LEVS, FILT2, EDGES)
  2. %
  3. % Reconstruct image from Laplacian pyramid, as created by buildLpyr.
  4. %
  5. % PYR is a vector containing the N pyramid subbands, ordered from fine
  6. % to coarse. INDICES is an Nx2 matrix containing the sizes of
  7. % each subband. This is compatible with the MatLab Wavelet toolbox.
  8. %
  9. % LEVS (optional) should be a list of levels to include, or the string
  10. % 'all' (default). The finest scale is number 1. The lowpass band
  11. % corresponds to lpyrHt(INDICES)+1.
  12. %
  13. % FILT2 (optional) can be a string naming a standard filter (see
  14. % namedFilter), or a vector which will be used for (separable)
  15. % convolution. Default = 'binom5'. EDGES specifies edge-handling,
  16. % and defaults to 'reflect1' (see corrDn).
  17. % Eero Simoncelli, 6/96
  18. function res = reconLpyr(pyr, ind, levs, filt2, edges)
  19. if (nargin < 2)
  20. error('First two arguments (PYR, INDICES) are required');
  21. end
  22. %%------------------------------------------------------------
  23. %% DEFAULTS:
  24. if (exist('levs') ~= 1)
  25. levs = 'all';
  26. end
  27. if (exist('filt2') ~= 1)
  28. filt2 = 'binom5';
  29. end
  30. if (exist('edges') ~= 1)
  31. edges= 'reflect1';
  32. end
  33. %%------------------------------------------------------------
  34. maxLev = 1+lpyrHt(ind);
  35. if strcmp(levs,'all')
  36. levs = [1:maxLev]';
  37. else
  38. if (any(levs > maxLev))
  39. error(sprintf('Level numbers must be in the range [1, %d].', maxLev));
  40. end
  41. levs = levs(:);
  42. end
  43. if isstr(filt2)
  44. filt2 = namedFilter(filt2);
  45. end
  46. filt2 = filt2(:);
  47. res_sz = ind(1,:);
  48. if any(levs > 1)
  49. int_sz = [ind(1,1), ind(2,2)];
  50. nres = reconLpyr( pyr(prod(res_sz)+1:size(pyr,1)), ...
  51. ind(2:size(ind,1),:), levs-1, filt2, edges);
  52. if (res_sz(1) == 1)
  53. res = upConv(nres, filt2', edges, [1 2], [1 1], res_sz);
  54. elseif (res_sz(2) == 1)
  55. res = upConv(nres, filt2, edges, [2 1], [1 1], res_sz);
  56. else
  57. hi = upConv(nres, filt2, edges, [2 1], [1 1], int_sz);
  58. res = upConv(hi, filt2', edges, [1 2], [1 1], res_sz);
  59. end
  60. else
  61. res = zeros(res_sz);
  62. end
  63. if any(levs == 1)
  64. res = res + pyrBand(pyr,ind,1);
  65. end