mkRamp.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. % IM = mkRamp(SIZE, DIRECTION, SLOPE, INTERCEPT, ORIGIN)
  2. %
  3. % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar)
  4. % containing samples of a ramp function, with given gradient DIRECTION
  5. % (radians, CW from X-axis, default = 0), SLOPE (per pixel, default =
  6. % 1), and a value of INTERCEPT (default = 0) at the ORIGIN (default =
  7. % (size+1)/2, [1 1] = upper left). All but the first argument are
  8. % optional.
  9. % Eero Simoncelli, 6/96. 2/97: adjusted coordinate system.
  10. function [res] = mkRamp(sz, dir, slope, intercept, origin)
  11. sz = sz(:);
  12. if (size(sz,1) == 1)
  13. sz = [sz,sz];
  14. end
  15. % -----------------------------------------------------------------
  16. % OPTIONAL args:
  17. if (exist('dir') ~= 1)
  18. dir = 0;
  19. end
  20. if (exist('slope') ~= 1)
  21. slope = 1;
  22. end
  23. if (exist('intercept') ~= 1)
  24. intercept = 0;
  25. end
  26. if (exist('origin') ~= 1)
  27. origin = (sz+1)/2;
  28. end
  29. % -----------------------------------------------------------------
  30. xinc = slope*cos(dir);
  31. yinc = slope*sin(dir);
  32. [xramp,yramp] = meshgrid( xinc*([1:sz(2)]-origin(2)), ...
  33. yinc*([1:sz(1)]-origin(1)) );
  34. res = intercept + xramp + yramp;