annotate scripts/image/image.m @ 9899:9f25290a35e8

more private function and subfunction changes
author John W. Eaton <jwe@octave.org>
date Tue, 01 Dec 2009 22:40:37 -0500
parents 16f53d29049f
children 2c01d24459fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003,
9245
16f53d29049f update copyright notices
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
2 ## 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
18 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
19
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
20 ## -*- texinfo -*-
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6164
diff changeset
21 ## @deftypefn {Function File} {} image (@var{img})
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6164
diff changeset
22 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{img})
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
23 ## Display a matrix as a color image. The elements of @var{x} are indices
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
24 ## into the current colormap, and the colormap will be scaled so that the
8325
b93ac0586e4b spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents: 7315
diff changeset
25 ## extremes of @var{x} are mapped to the extremes of the colormap.
3651
c2305b99fbd7 [project @ 2000-03-31 07:12:29 by jwe]
jwe
parents: 3457
diff changeset
26 ##
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents: 6088
diff changeset
27 ## It first tries to use @code{gnuplot}, then @code{display} from
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents: 6088
diff changeset
28 ## @code{ImageMagick}, then @code{xv}, and then @code{xloadimage}.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents: 6088
diff changeset
29 ## The actual program used can be changed using the @code{image_viewer}
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents: 6088
diff changeset
30 ## function.
3714
38ff09748e26 [project @ 2000-08-25 06:10:30 by jwe]
jwe
parents: 3651
diff changeset
31 ##
3651
c2305b99fbd7 [project @ 2000-03-31 07:12:29 by jwe]
jwe
parents: 3457
diff changeset
32 ## The axis values corresponding to the matrix elements are specified in
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
33 ## @var{x} and @var{y}. If you're not using gnuplot 4.2 or later, these
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents: 6088
diff changeset
34 ## variables are ignored.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents: 6088
diff changeset
35 ## @seealso{imshow, imagesc, colormap, image_viewer}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
36 ## @end deftypefn
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
37
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 2847
diff changeset
38 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
39 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
40 ## Adapted-By: jwe
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 686
diff changeset
41
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
42 function retval = image (varargin)
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
43
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
44 [ax, varargin, nargin] = __plt_get_axis_arg__ ("image", varargin{:});
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
45
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
46 firstnonnumeric = Inf;
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
47 for i = 1 : nargin
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
48 if (! isnumeric (varargin{i}))
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
49 firstnonnumeric = i;
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
50 break;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
51 endif
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
52 endfor
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
53
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
54 if (nargin == 0 || firstnonnumeric == 1)
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
55 img = loadimage ("default.img");
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
56 x = y = [];
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
57 elseif (nargin == 1 || firstnonnumeric == 2)
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
58 img = varargin{1};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
59 x = y = [];
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
60 elseif (nargin == 2 || firstnonnumeric == 3)
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
61 print_usage ();
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
62 else
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
63 x = varargin{1};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
64 y = varargin{2};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
65 img = varargin{3};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
66 firstnonnumeric = 4;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
67 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
68
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
69 oldax = gca ();
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
70 unwind_protect
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
71 axes (ax);
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
72 h = __img__ (x, y, img, varargin {firstnonnumeric:end});
7315
3ceb12c499e9 [project @ 2007-12-13 21:35:36 by jwe]
jwe
parents: 7276
diff changeset
73 set (ax, "layer", "top");
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
74 unwind_protect_cleanup
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
75 axes (oldax);
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
76 end_unwind_protect
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
77
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
78 if (nargout > 0)
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
79 retval = h;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
80 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
81
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
82 endfunction
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
83
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
84 ## Generic image creation.
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
85 ##
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
86 ## The axis values corresponding to the matrix elements are specified in
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
87 ## @var{x} and @var{y}. If you're not using gnuplot 4.2 or later, these
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
88 ## variables are ignored.
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
89
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
90 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
91 ## Created: July 1994
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
92 ## Adapted-By: jwe
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
93
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
94 function h = __img__ (x, y, img, varargin)
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
95
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
96 newplot ();
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
97
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
98 if (isempty (img))
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
99 error ("__img__: matrix is empty");
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
100 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
101
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
102 if (isempty (x))
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
103 x = [1, columns(img)];
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
104 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
105
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
106 if (isempty (y))
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
107 y = [1, rows(img)];
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
108 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
109
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
110 xdata = [x(1), x(end)];
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
111 ydata = [y(1), y(end)];
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
112
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
113 xlim = [x(1)-0.5, x(end)+0.5];
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
114 ylim = [y(1)-0.5, y(end)+0.5];
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
115
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
116 ca = gca ();
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
117
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
118 tmp = __go_image__ (ca, "cdata", img, "xdata", xdata, "ydata", ydata,
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
119 "cdatamapping", "direct", varargin {:});
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
120
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
121 ## FIXME -- how can we do this and also get the {x,y}limmode
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
122 ## properties to remain "auto"? I suppose this adjustment should
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
123 ## happen automatically in axes::update_axis_limits instead of
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
124 ## explicitly setting the values here. But then what information is
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
125 ## available to axes::update_axis_limits to determine that the
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
126 ## adjustment is necessary?
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
127 set (ca, "xlim", xlim, "ylim", ylim);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
128
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
129 if (ndims (img) == 3)
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
130 if (isinteger (img))
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
131 c = class (img);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
132 mn = intmin (c);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
133 mx = intmax (c);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
134 set (ca, "clim", double ([mn, mx]));
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
135 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
136 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
137
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
138 set (ca, "view", [0, 90]);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
139
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
140 if (strcmp (get (ca, "nextplot"), "replace"))
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
141 set (ca, "ydir", "reverse");
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
142 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
143
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
144 if (nargout > 0)
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
145 h = tmp;
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
146 endif
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
147
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
148 endfunction