home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / image / saveimg.m < prev   
Text File  |  1998-05-23  |  1KB  |  46 lines

  1. ## Copyright (C) 1996 Klaus Gebhardt
  2. ##
  3. ## Save a matrix to disk in image format.
  4. ##
  5. ## saveimg (filename, x) saves matrix x to file filename in octaves
  6. ## image format.  The current colormap is saved in the file also.
  7. ##
  8. ## saveimg (filename, x, format, map) saves the image along with the
  9. ## specified colormap in the specified format.
  10. ##
  11.  
  12. ## Author: Klaus Gebhardt <gebhardt@crunch.ikp.physik.th-darmstadt.de>
  13. ## Created: November 1996
  14.  
  15. function saveimg (filename, img, img_form, map, opt)
  16.  
  17.   if (nargin < 2 || nargin > 5)
  18.     usage ("saveimg (filename, matrix, [format, [colormap, [opt]]])");
  19.   endif
  20.  
  21.   if (nargin < 4)
  22.     map = colormap ();
  23.   endif
  24.  
  25.   if (nargin < 3)
  26.     img_form = "img";
  27.   elseif (! isstr (img_form))
  28.     error ("image format specification must be a string");
  29.   endif
  30.  
  31.   if (! is_mat (img))
  32.     warning ("image variable is not a matrix");
  33.   endif
  34.  
  35.   if (! isstr (filename))
  36.     error ("file name must be a string");
  37.   endif
  38.  
  39.   if (nargin < 5)
  40.     eval (sprintf ("%s_enc (filename, map, img);", img_form));
  41.   else
  42.     eval (sprintf ("%s_enc (filename, map, img, opt);", img_form));
  43.   endif
  44.  
  45. endfunction
  46.