Mercurial > octave-nkf
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 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, |
9245 | 2 ## 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
1024 | 19 |
3381 | 20 ## -*- texinfo -*- |
6257 | 21 ## @deftypefn {Function File} {} image (@var{img}) |
22 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{img}) | |
3373 | 23 ## Display a matrix as a color image. The elements of @var{x} are indices |
7189 | 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 | 26 ## |
6164 | 27 ## It first tries to use @code{gnuplot}, then @code{display} from |
28 ## @code{ImageMagick}, then @code{xv}, and then @code{xloadimage}. | |
29 ## The actual program used can be changed using the @code{image_viewer} | |
30 ## function. | |
3714 | 31 ## |
3651 | 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 | 34 ## variables are ignored. |
35 ## @seealso{imshow, imagesc, colormap, image_viewer} | |
3373 | 36 ## @end deftypefn |
559 | 37 |
3202 | 38 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 39 ## Created: July 1994 |
40 ## Adapted-By: jwe | |
904 | 41 |
7189 | 42 function retval = image (varargin) |
43 | |
7276 | 44 [ax, varargin, nargin] = __plt_get_axis_arg__ ("image", varargin{:}); |
45 | |
46 firstnonnumeric = Inf; | |
47 for i = 1 : nargin | |
48 if (! isnumeric (varargin{i})) | |
49 firstnonnumeric = i; | |
50 break; | |
7189 | 51 endif |
7276 | 52 endfor |
53 | |
54 if (nargin == 0 || firstnonnumeric == 1) | |
55 img = loadimage ("default.img"); | |
56 x = y = []; | |
57 elseif (nargin == 1 || firstnonnumeric == 2) | |
58 img = varargin{1}; | |
59 x = y = []; | |
60 elseif (nargin == 2 || firstnonnumeric == 3) | |
61 print_usage (); | |
7189 | 62 else |
7276 | 63 x = varargin{1}; |
64 y = varargin{2}; | |
65 img = varargin{3}; | |
66 firstnonnumeric = 4; | |
7189 | 67 endif |
68 | |
7276 | 69 oldax = gca (); |
70 unwind_protect | |
71 axes (ax); | |
72 h = __img__ (x, y, img, varargin {firstnonnumeric:end}); | |
7315 | 73 set (ax, "layer", "top"); |
7276 | 74 unwind_protect_cleanup |
75 axes (oldax); | |
76 end_unwind_protect | |
77 | |
7189 | 78 if (nargout > 0) |
7276 | 79 retval = h; |
7189 | 80 endif |
81 | |
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 |