[Index for tmp_for_tar/imgio] [Return to Master Index]

ims_save

(tmp_for_tar/imgio/ims_save.m)


Function Synopsis

ok = ims_save (ims, file, fmt)

Help text

       ok = ims_save (ims, file [, fmt])

 Attempts to save image structure ims in file.

 The image format used depends on fmt, if this argument is provided, or on
 the extension of file, if any, or, by default in ppm or pgm.

 fmt may be one of "ppm", "pgm", "pnm", "ppm-ascii", "pgm-ascii",
 "pnm-ascii", "gif", "jpg", "fi", "ps" or "img".

 If fmt is one of "ppm-ascii", "pgm-ascii", "pnm-ascii", an ascii file is
 produced.

 Last modified: Setembro 2002



Cross-Reference Information

This function is called by

Listing of function file tmp_for_tar/imgio/ims_save.m

##       ok = ims_save (ims, file [, fmt])
## 
## Attempts to save image structure ims in file.
##
## The image format used depends on fmt, if this argument is provided, or on
## the extension of file, if any, or, by default in ppm or pgm.
##
## fmt may be one of "ppm", "pgm", "pnm", "ppm-ascii", "pgm-ascii",
## "pnm-ascii", "gif", "jpg", "fi", "ps" or "img".
##
## If fmt is one of "ppm-ascii", "pgm-ascii", "pnm-ascii", an ascii file is
## produced.
##

## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: Setembro 2002

function ok = ims_save (ims, file, fmt)

ok = 1 ;

if nargin < 1,
  printf ("usage : ims_save (ims [,file [,fmt]] )");
  ok = 0 ;
  return
end

if nargin < 2,			# Guess file name
  if struct_contains (ims, "file"),
    file = ims.file ;
  else
    printf ("ims_save can't determine file name\n");
    ok = 0 ;
    keyboard
  end
end

if nargin < 3,			# Guess file format
  if struct_contains(ims, "fmt"), 
    fmt = ims.fmt ;
  else
    fmt = filename_ext (file);
    if ! length (fmt),
				# Default is ppm / pgm
      if ims.rgb, fmt = "ppm";
      else        fmt = "pgm";
      end
      file = [file, ".", fmt];
      ## printf ("ims_save can't determine file format\n");
      ## keyboard
    end
  end
end
				# Now, fmt and file are set

scale =  ims.maxval != 255 ;

if     strcmp (fmt, "ppm-ascii"), fmt = "ppm"; ascii = 1; 
elseif strcmp (fmt, "pgm-ascii"), fmt = "pgm"; ascii = 1; 
elseif strcmp (fmt, "pnm-ascii"), fmt = "pnm"; ascii = 1;
else                                           ascii = 0;
end

if strcmp(fmt,"ppm") || strcmp(fmt,"pnm") || strcmp(fmt,"pgm"),
  
  rgb = fmt(2)=="p" || fmt(2)=="n" && ims.rgb;

  if    !ims.rgb && fmt(2) == "p",
    writepnm (file, gray2rgb ( ims.im ), rgb, scale, ascii);
  elseif ims.rgb && fmt(2) == "g", 
    writepnm (file, rgb2gray ( ims.im ), rgb, scale, ascii);
  else
    writepnm (file, ims.im, rgb, scale, ascii);
  end


    
elseif strcmp(fmt,"gif"),

  if ims.rgb, writegif (file, ims.im, scale);
  else        writegraygif (file, ims.im, scale);
  end

elseif strcmp(fmt,"jpg"),

  if ims.rgb, writejpg (file, ims.im, scale);
  else        writegrayjpg (file, ims.im, scale);
  end

elseif strcmp(fmt,"fi"),

  if ims.rgb,   warning ("ims_save a color image to gray file (fi)\n"); end
  writefi (file, ims.im);

elseif findstr([" ",fmt," "]," img ps "),

  if ims.rgb, map = [0,0.5,1] ; else map = [0,0,0]; end
  saveimage (file, ims.im, fmt, map);

else
  printf ("ims_save doesn't what to do with format '%s'\n",fmt);
  ok = 0 ;
  keyboard
end

Produced by oct2html on Sat Sep 14 9:47:03 2002
Cross-Directory links are: ON