upConv.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. % RES = upConv(IM, FILT, EDGES, STEP, START, STOP, RES)
  2. %
  3. % Upsample matrix IM, followed by convolution with matrix FILT. These
  4. % arguments should be 1D or 2D matrices, and IM must be larger (in
  5. % 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
  15. % 'dont-compute' - Zero output when filter overhangs OUTPUT boundaries
  16. %
  17. % Upsampling factors are determined by STEP (optional, default=[1 1]),
  18. % 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 =
  22. % step .* (size(IM) + floor((start-1)./step))).
  23. %
  24. % RES is an optional result matrix. The convolution result will be
  25. % destructively added into this matrix. If this argument is passed, the
  26. % result matrix will not be returned. DO NOT USE THIS ARGUMENT IF
  27. % YOU DO NOT UNDERSTAND WHAT THIS MEANS!!
  28. %
  29. % NOTE: this operation corresponds to multiplication of a signal
  30. % vector by a matrix whose columns contain copies of the time-reversed
  31. % (or space-reversed) FILT shifted by multiples of STEP. See corrDn.m
  32. % for the operation corresponding to the transpose of this matrix.
  33. % Eero Simoncelli, 6/96. revised 2/97.
  34. function result = upConv(im,filt,edges,step,start,stop,res)
  35. %% THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
  36. fprintf(1,'WARNING: You should compile the MEX version of "upConv.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');
  37. %------------------------------------------------------------
  38. %% OPTIONAL ARGS:
  39. if (exist('edges') == 1)
  40. if (strcmp(edges,'reflect1') ~= 1)
  41. warning('Using REFLECT1 edge-handling (use MEX code for other options).');
  42. end
  43. end
  44. if (exist('step') ~= 1)
  45. step = [1,1];
  46. end
  47. if (exist('start') ~= 1)
  48. start = [1,1];
  49. end
  50. % A multiple of step
  51. if (exist('stop') ~= 1)
  52. stop = step .* (floor((start-ones(size(start)))./step)+size(im))
  53. end
  54. if ( ceil((stop(1)+1-start(1)) / step(1)) ~= size(im,1) )
  55. error('Bad Y result dimension');
  56. end
  57. if ( ceil((stop(2)+1-start(2)) / step(2)) ~= size(im,2) )
  58. error('Bad X result dimension');
  59. end
  60. if (exist('res') ~= 1)
  61. res = zeros(stop-start+1);
  62. end
  63. %------------------------------------------------------------
  64. tmp = zeros(size(res));
  65. tmp(start(1):step(1):stop(1),start(2):step(2):stop(2)) = im;
  66. result = rconv2(tmp,filt) + res;