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 ## |
3714
|
28 ## It first tries to use @code{display} from @code{ImageMagick} then |
|
29 ## @code{xv} and then @code{xloadimage}. |
|
30 ## |
3651
|
31 ## The axis values corresponding to the matrix elements are specified in |
|
32 ## @var{x} and @var{y}. At present they are ignored. |
3373
|
33 ## @end deftypefn |
3457
|
34 ## @seealso{imshow, imagesc, and colormap} |
559
|
35 |
3202
|
36 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
37 ## Created: July 1994 |
|
38 ## Adapted-By: jwe |
904
|
39 |
3651
|
40 function image (x, y, A, zoom) |
559
|
41 |
|
42 if (nargin == 0) |
2303
|
43 ## Load Bobbie Jo Richardson (Born 3/16/94) |
3714
|
44 A = loadimage ("default.img"); |
559
|
45 zoom = 2; |
1024
|
46 elseif (nargin == 1) |
3651
|
47 A = x; |
|
48 zoom = []; |
|
49 x = y = []; |
|
50 elseif (nargin == 2) |
|
51 A = x; |
|
52 zoom = y; |
|
53 x = y = []; |
|
54 elseif (nargin == 3) |
|
55 zoom = []; |
|
56 elseif (nargin > 4) |
|
57 usage ("image (matrix, zoom) or image (x, y, matrix, zoom)"); |
559
|
58 endif |
|
59 |
3651
|
60 if isempty(zoom) |
|
61 ## Find an integer scale factor which sets the image to |
|
62 ## approximately the size of the screen. |
|
63 zoom = min ([350/rows(A), 600/columns(A), 4]); |
|
64 if (zoom >= 1) |
|
65 zoom = floor (zoom); |
|
66 else |
|
67 zoom = 1 / ceil (1/zoom); |
|
68 endif |
|
69 endif |
2458
|
70 ppm_name = tmpnam (); |
559
|
71 |
3651
|
72 saveimage (ppm_name, A, "ppm"); |
559
|
73 |
2303
|
74 ## Start the viewer. Try xv, then xloadimage. |
559
|
75 |
1024
|
76 xv = sprintf ("xv -expand %f %s", zoom, ppm_name); |
2458
|
77 |
1024
|
78 xloadimage = sprintf ("xloadimage -zoom %f %s", zoom*100, ppm_name); |
2458
|
79 |
3714
|
80 ## ImageMagick: |
|
81 im_display = sprintf ("display -geometry %f%% %s", zoom*100, ppm_name); |
|
82 |
1024
|
83 rm = sprintf ("rm -f %s", ppm_name); |
559
|
84 |
2458
|
85 ## Need to let the shell clean up the tmp file because we are putting |
|
86 ## the viewer in the background. |
|
87 |
3714
|
88 system (sprintf ("( %s || %s || %s && %s ) > /dev/null 2>&1 &", |
|
89 im_display, xv, xloadimage, rm)); |
559
|
90 |
|
91 endfunction |