2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
1024
|
19 |
3381
|
20 ## -*- texinfo -*- |
3373
|
21 ## @deftypefn {Function File} {} image (@var{x}, @var{zoom}) |
3651
|
22 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{A}, @var{zoom}) |
3373
|
23 ## Display a matrix as a color image. The elements of @var{x} are indices |
|
24 ## into the current colormap and should have values between 1 and the |
3651
|
25 ## length of the colormap. If @var{zoom} is omitted, the image will be |
|
26 ## scaled to fit within 600x350 (to a max of 4). |
|
27 ## |
|
28 ## The axis values corresponding to the matrix elements are specified in |
|
29 ## @var{x} and @var{y}. At present they are ignored. |
3373
|
30 ## @end deftypefn |
3457
|
31 ## @seealso{imshow, imagesc, and colormap} |
559
|
32 |
3202
|
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
34 ## Created: July 1994 |
|
35 ## Adapted-By: jwe |
904
|
36 |
3651
|
37 function image (x, y, A, zoom) |
559
|
38 |
|
39 if (nargin == 0) |
2303
|
40 ## Load Bobbie Jo Richardson (Born 3/16/94) |
1024
|
41 x = loadimage ("default.img"); |
559
|
42 zoom = 2; |
1024
|
43 elseif (nargin == 1) |
3651
|
44 A = x; |
|
45 zoom = []; |
|
46 x = y = []; |
|
47 elseif (nargin == 2) |
|
48 A = x; |
|
49 zoom = y; |
|
50 x = y = []; |
|
51 elseif (nargin == 3) |
|
52 zoom = []; |
|
53 elseif (nargin > 4) |
|
54 usage ("image (matrix, zoom) or image (x, y, matrix, zoom)"); |
559
|
55 endif |
|
56 |
3651
|
57 if isempty(zoom) |
|
58 ## Find an integer scale factor which sets the image to |
|
59 ## approximately the size of the screen. |
|
60 zoom = min ([350/rows(A), 600/columns(A), 4]); |
|
61 if (zoom >= 1) |
|
62 zoom = floor (zoom); |
|
63 else |
|
64 zoom = 1 / ceil (1/zoom); |
|
65 endif |
|
66 endif |
2458
|
67 ppm_name = tmpnam (); |
559
|
68 |
3651
|
69 saveimage (ppm_name, A, "ppm"); |
559
|
70 |
2303
|
71 ## Start the viewer. Try xv, then xloadimage. |
559
|
72 |
1024
|
73 xv = sprintf ("xv -expand %f %s", zoom, ppm_name); |
2458
|
74 |
1024
|
75 xloadimage = sprintf ("xloadimage -zoom %f %s", zoom*100, ppm_name); |
2458
|
76 |
1024
|
77 rm = sprintf ("rm -f %s", ppm_name); |
559
|
78 |
2458
|
79 ## Need to let the shell clean up the tmp file because we are putting |
|
80 ## the viewer in the background. |
|
81 |
3651
|
82 system (sprintf ("( %s || %s && %s ) > /dev/null 2>&1 &", |
|
83 xv, xloadimage, rm)); |
559
|
84 |
|
85 endfunction |