comparison scripts/image/saveimage.m @ 559:4e826edfbc56

[project @ 1994-07-25 22:18:28 by jwe] Initial revision
author jwe
date Mon, 25 Jul 1994 22:19:05 +0000
parents
children 0faebdd7df57
comparison
equal deleted inserted replaced
558:faf108b99d21 559:4e826edfbc56
1 function saveimage(filename,X,img_form,map)
2 #Save a matrix to disk in image format.
3 #
4 #saveimage(filename,x) saves matrix x to file filename in octave's image
5 #format. The current colormap is saved in the file also.
6 #
7 #saveimage(filename,x,"img") saves the image in the default format and
8 #is the same as saveimage(filename,x).
9 #
10 #saveimage(filename,x,"ppm") saves the image in ppm format instead of
11 #the default octave image format.
12 #
13 #saveimage(filename,x,"ps") saves the image in PostScript format instead
14 #of the default octave image format. (Note: images saved in PostScript format
15 #can not be read back into octave with loadimage.)
16 #
17 #saveimage(filename,x,format,map) saves the image along with the specified
18 #colormap in the specified format.
19 #
20 #Note: If the colormap contains only two entries and these entries are black
21 #and white, the bitmap ppm and PostScript formats are used. If the image is
22 #a gray scale image (the entries within each row of the colormap are equal)
23 #the gray scale ppm and PostScript image formats are used, otherwise the full
24 #color formats are used.
25 #
26 #SEE ALSO: loadimage, save, load, colormap
27
28 global IMAGEDIR
29
30 if(nargin < 2)
31 error("usage: saveimage(filename,matrix,[format, [colormap]])");
32 elseif(nargin == 2)
33 if(!isstr(filename))
34 error("File name must be a string.");
35 endif
36 map = colormap;
37 img_form = "img";
38 elseif(nargin == 3)
39 if(!isstr(img_form))
40 error("Image format specification must be a string");
41 endif
42 map = colormap;
43 endif
44
45 if (strcmp(img_form,"img") == 1)
46 oct_file = filename;
47 elseif (strcmp(img_form,"ppm") == 1)
48 # We need a temporary octave image file name.
49 oct_file = sprintf("image.%s.img",num2str(fix(rand*10000)));
50 ppm_file = filename;
51 elseif (strcmp(img_form,"ps") == 1)
52 # We need a temporary octave image file name.
53 oct_file = sprintf("image.%s.img",num2str(fix(rand*10000)));
54 ps_file = filename;
55 endif
56
57 # Save image in octave image file format
58 eval(['save ', oct_file, ' map X']);
59
60 # Convert to another format if requested.
61 if (strcmp(img_form,"ppm") == 1)
62 octtopnm = sprintf([IMAGEDIR,"/octtopnm %s > %s"],oct_file,filename);
63 rm = sprintf("rm -f %s",oct_file);
64 shell_cmd(octtopnm);
65 shell_cmd(rm);
66 elseif (strcmp(img_form,"ps") == 1)
67 octtopnm = sprintf([IMAGEDIR,"/octtopnm %s"],oct_file);
68 ppmtops = sprintf("pnmtops > %s 2> /dev/null", filename);
69 octtops = [ octtopnm, " | ", ppmtops ];
70 rm = sprintf("rm -f %s",oct_file);
71 shell_cmd(octtops);
72 shell_cmd(rm);
73 endif
74
75 endfunction