mkAngle.m 788 B

1234567891011121314151617181920212223242526272829303132
  1. % IM = mkAngle(SIZE, PHASE, ORIGIN)
  2. %
  3. % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar)
  4. % containing samples of the polar angle (in radians, CW from the
  5. % X-axis, ranging from -pi to pi), relative to angle PHASE (default =
  6. % 0), about ORIGIN pixel (default = (size+1)/2).
  7. % Eero Simoncelli, 6/96.
  8. function [res] = mkAngle(sz, phase, origin)
  9. sz = sz(:);
  10. if (size(sz,1) == 1)
  11. sz = [sz,sz];
  12. end
  13. % -----------------------------------------------------------------
  14. % OPTIONAL args:
  15. if (exist('origin') ~= 1)
  16. origin = (sz+1)/2;
  17. end
  18. % -----------------------------------------------------------------
  19. [xramp,yramp] = meshgrid( [1:sz(2)]-origin(2), [1:sz(1)]-origin(1) );
  20. res = atan2(yramp,xramp);
  21. if (exist('phase') == 1)
  22. res = mod(res+(pi-phase),2*pi)-pi;
  23. end