blurDn.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. % RES = blurDn(IM, LEVELS, FILT)
  2. %
  3. % Blur and downsample an image. The blurring is done with filter
  4. % kernel specified by FILT (default = 'binom5'), which can be a string
  5. % (to be passed to namedFilter), a vector (applied separably as a 1D
  6. % convolution kernel in X and Y), or a matrix (applied as a 2D
  7. % convolution kernel). The downsampling is always by 2 in each
  8. % direction.
  9. %
  10. % The procedure is applied recursively LEVELS times (default=1).
  11. % Eero Simoncelli, 3/97.
  12. function res = blurDn(im, nlevs, filt)
  13. %------------------------------------------------------------
  14. %% OPTIONAL ARGS:
  15. if (exist('nlevs') ~= 1)
  16. nlevs = 1;
  17. end
  18. if (exist('filt') ~= 1)
  19. filt = 'binom5';
  20. end
  21. %------------------------------------------------------------
  22. if isstr(filt)
  23. filt = namedFilter(filt);
  24. end
  25. filt = filt/sum(filt(:));
  26. if nlevs > 1
  27. im = blurDn(im,nlevs-1,filt);
  28. end
  29. if (nlevs >= 1)
  30. if (any(size(im)==1))
  31. if (~any(size(filt)==1))
  32. error('Cant apply 2D filter to 1D signal');
  33. end
  34. if (size(im,2)==1)
  35. filt = filt(:);
  36. else
  37. filt = filt(:)';
  38. end
  39. res = corrDn(im,filt,'reflect1',(size(im)~=1)+1);
  40. elseif (any(size(filt)==1))
  41. filt = filt(:);
  42. res = corrDn(im,filt,'reflect1',[2 1]);
  43. res = corrDn(res,filt','reflect1',[1 2]);
  44. else
  45. res = corrDn(im,filt,'reflect1',[2 2]);
  46. end
  47. else
  48. res = im;
  49. end