home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / image / imagesc.m < prev    next >
Text File  |  1996-07-11  |  2KB  |  60 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Scale and display a matrix as an image.
  21. ##
  22. ## imagesc(x) displays a scaled version of the matrix x.  The matrix is
  23. ## scaled so that its entries are indices into the current colormap.
  24. ## The scaled matrix is returned.
  25. ##
  26. ## imagesc (x, zoom) sets the magnification, the default value is 4.
  27. ##
  28. ## SEE ALSO: image, imshow
  29.  
  30. ## Author: Tony Richardson <amr@mpl.ucsd.edu>
  31. ## Created: July 1994
  32. ## Adapted-By: jwe
  33.  
  34. function x = imagesc (x, zoom)
  35.  
  36.   if (nargin < 1 || nargin > 2)
  37.     usage ("image (matrix, [zoom])");
  38.   elseif (nargin == 1)
  39.     zoom = 4;
  40.   endif
  41.  
  42.   [ high, wide ] = size (x);
  43.  
  44.   maxval = max (max (x));
  45.   minval = min (min (x));
  46.  
  47.   ## Rescale matrix so that all values are in the range 0 to
  48.   ## length (colormap) inclusive.
  49.  
  50.   if (maxval == minval)
  51.     x = ones (high, wide);
  52.   else
  53.     ## Rescale values to between 1 and length (colormap) inclusive.
  54.     x = fix ((x - minval) / (maxval - minval) * (length (colormap) - 1)) + 1;
  55.   endif
  56.  
  57.   image (x, zoom);
  58.  
  59. endfunction
  60.