corrDn.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. % RES = corrDn(IM, FILT, EDGES, STEP, START, STOP)
  2. %
  3. % Compute correlation of matrices IM with FILT, followed by
  4. % downsampling. These arguments should be 1D or 2D matrices, and IM
  5. % must be larger (in both dimensions) than FILT. The origin of filt
  6. % is assumed to be floor(size(filt)/2)+1.
  7. %
  8. % EDGES is a string determining boundary handling:
  9. % 'circular' - Circular convolution
  10. % 'reflect1' - Reflect about the edge pixels
  11. % 'reflect2' - Reflect, doubling the edge pixels
  12. % 'repeat' - Repeat the edge pixels
  13. % 'zero' - Assume values of zero outside image boundary
  14. % 'extend' - Reflect and invert (continuous values and derivs)
  15. % 'dont-compute' - Zero output when filter overhangs input boundaries
  16. %
  17. % Downsampling factors are determined by STEP (optional, default=[1 1]),
  18. % which should be a 2-vector [y,x].
  19. %
  20. % The window over which the convolution occurs is specfied by START
  21. % (optional, default=[1,1], and STOP (optional, default=size(IM)).
  22. %
  23. % NOTE: this operation corresponds to multiplication of a signal
  24. % vector by a matrix whose rows contain copies of the FILT shifted by
  25. % multiples of STEP. See upConv.m for the operation corresponding to
  26. % the transpose of this matrix.
  27. % Eero Simoncelli, 6/96, revised 2/97.
  28. function res = corrDn(im, filt, edges, step, start, stop)
  29. %% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
  30. fprintf(1,'WARNING: You should compile the MEX version of "corrDn.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster, and provides more boundary-handling options.\n');
  31. %------------------------------------------------------------
  32. %% OPTIONAL ARGS:
  33. if (exist('edges') == 1)
  34. if (strcmp(edges,'reflect1') ~= 1)
  35. warning('Using REFLECT1 edge-handling (use MEX code for other options).');
  36. end
  37. end
  38. if (exist('step') ~= 1)
  39. step = [1,1];
  40. end
  41. if (exist('start') ~= 1)
  42. start = [1,1];
  43. end
  44. if (exist('stop') ~= 1)
  45. stop = size(im);
  46. end
  47. %------------------------------------------------------------
  48. % Reverse order of taps in filt, to do correlation instead of convolution
  49. filt = filt(size(filt,1):-1:1,size(filt,2):-1:1);
  50. tmp = rconv2(im,filt);
  51. res = tmp(start(1):step(1):stop(1),start(2):step(2):stop(2));