mkDisc.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. % IM = mkDisc(SIZE, RADIUS, ORIGIN, TWIDTH, VALS)
  2. %
  3. % Make a "disk" image. SIZE specifies the matrix size, as for
  4. % zeros(). RADIUS (default = min(size)/4) specifies the radius of
  5. % the disk. ORIGIN (default = (size+1)/2) specifies the
  6. % location of the disk center. TWIDTH (in pixels, default = 2)
  7. % specifies the width over which a soft threshold transition is made.
  8. % VALS (default = [0,1]) should be a 2-vector containing the
  9. % intensity value inside and outside the disk.
  10. % Eero Simoncelli, 6/96.
  11. function [res] = mkDisc(sz, rad, origin, twidth, vals)
  12. if (nargin < 1)
  13. error('Must pass at least a size argument');
  14. end
  15. sz = sz(:);
  16. if (size(sz,1) == 1)
  17. sz = [sz sz];
  18. end
  19. %------------------------------------------------------------
  20. % OPTIONAL ARGS:
  21. if (exist('rad') ~= 1)
  22. rad = min(sz(1),sz(2))/4;
  23. end
  24. if (exist('origin') ~= 1)
  25. origin = (sz+1)./2;
  26. end
  27. if (exist('twidth') ~= 1)
  28. twidth = 2;
  29. end
  30. if (exist('vals') ~= 1)
  31. vals = [1,0];
  32. end
  33. %------------------------------------------------------------
  34. res = mkR(sz,1,origin);
  35. if (abs(twidth) < realmin)
  36. res = vals(2) + (vals(1) - vals(2)) * (res <= rad);
  37. else
  38. [Xtbl,Ytbl] = rcosFn(twidth, rad, [vals(1), vals(2)]);
  39. res = pointOp(res, Ytbl, Xtbl(1), Xtbl(2)-Xtbl(1), 0);
  40. %
  41. % OLD interp1 VERSION:
  42. % res = res(:);
  43. % Xtbl(1) = min(res);
  44. % Xtbl(size(Xtbl,2)) = max(res);
  45. % res = reshape(interp1(Xtbl,Ytbl,res), sz(1), sz(2));
  46. %
  47. end