function imgsc = scaleimage(img, range) %SCALEIMAGE Scale the image to a specified z-range. % % I = SCALEIMAGE(IMG, ZRANGE) % % SCALEIMAGE scale the image IMG using the ZRANGE % information and the global variable MAPSIZE that % define the colormap size. If zrange is omitted the % image is scale to the min and max values. % % See also IMAGESC. % % Claudio 25 Feb. 1995. % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % global MapSize; if nargin ==1 range=[min(min(img)) max(max(img))]; end if isempty(range) range=[min(min(img)) max(max(img))]; end imin = range(1); imax = range(2); if (imax-imin)==0 imin=0; imax=imin+1e-12; end imgsc = min(MapSize,round((MapSize-1)*(img-imin)/(imax-imin))+1); return