function y=scale(x,min,max)
%SCALE	Scale an image to a specific dynamic range
%	y=scale(x) scales the image x to the range 0:255
%	y=scale(x,min,max) scales the image x to the range min:max

if nargin<2,
  min=0;
  max=255;
end

y=(x-min2(x))*(max-min)/(max2(x)-min2(x)) + min;