Mercurial > octave
annotate scripts/image/image.m @ 10817:d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 25 Jul 2010 22:27:08 -0700 |
parents | be55736a0783 |
children | 947adebb1336 |
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 -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10704
diff
changeset
|
21 ## @deftypefn {Function File} {} image (@var{img}) |
6257 | 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. |
10817
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
35 ## |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
36 ## Implementation Note: The origin (0, 0) for images is located in the |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
37 ## upper left. For ordinary plots, the origin is located in the lower |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
38 ## left. Octave handles this inversion by plotting the data normally, |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
39 ## and then reversing the direction of the y-axis by setting the |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
40 ## @code{ydir) property to "reverse". This has implications whenever |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
41 ## an image and an ordinary plot need to be overlaid. The recommended |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
42 ## solution is to display the image and then plot the reversed ydata |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
43 ## using, for example, @code{flipud (ydata,1)}. |
6164 | 44 ## @seealso{imshow, imagesc, colormap, image_viewer} |
3373 | 45 ## @end deftypefn |
559 | 46 |
3202 | 47 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 48 ## Created: July 1994 |
49 ## Adapted-By: jwe | |
904 | 50 |
7189 | 51 function retval = image (varargin) |
52 | |
7276 | 53 [ax, varargin, nargin] = __plt_get_axis_arg__ ("image", varargin{:}); |
54 | |
55 firstnonnumeric = Inf; | |
56 for i = 1 : nargin | |
57 if (! isnumeric (varargin{i})) | |
58 firstnonnumeric = i; | |
59 break; | |
7189 | 60 endif |
7276 | 61 endfor |
62 | |
63 if (nargin == 0 || firstnonnumeric == 1) | |
10650
f0dc41c824ce
Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents:
10433
diff
changeset
|
64 img = imread ("default.img"); |
7276 | 65 x = y = []; |
66 elseif (nargin == 1 || firstnonnumeric == 2) | |
67 img = varargin{1}; | |
68 x = y = []; | |
69 elseif (nargin == 2 || firstnonnumeric == 3) | |
70 print_usage (); | |
7189 | 71 else |
7276 | 72 x = varargin{1}; |
73 y = varargin{2}; | |
74 img = varargin{3}; | |
75 firstnonnumeric = 4; | |
7189 | 76 endif |
77 | |
7276 | 78 oldax = gca (); |
79 unwind_protect | |
80 axes (ax); | |
81 h = __img__ (x, y, img, varargin {firstnonnumeric:end}); | |
7315 | 82 set (ax, "layer", "top"); |
7276 | 83 unwind_protect_cleanup |
84 axes (oldax); | |
85 end_unwind_protect | |
86 | |
7189 | 87 if (nargout > 0) |
7276 | 88 retval = h; |
7189 | 89 endif |
90 | |
91 endfunction | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
92 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
93 ## Generic image creation. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
94 ## |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
95 ## 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
|
96 ## @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
|
97 ## variables are ignored. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
98 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
99 ## 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
|
100 ## Created: July 1994 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
101 ## Adapted-By: jwe |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
102 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
103 function h = __img__ (x, y, img, varargin) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
104 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
105 newplot (); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
106 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
107 if (isempty (img)) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
108 error ("__img__: matrix is empty"); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
109 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
110 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
111 if (isempty (x)) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
112 x = [1, columns(img)]; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
113 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
114 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
115 if (isempty (y)) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
116 y = [1, rows(img)]; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
117 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
118 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
119 xdata = [x(1), x(end)]; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
120 ydata = [y(1), y(end)]; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
121 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
122 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
|
123 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
|
124 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
125 ca = gca (); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
126 |
10817
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
127 tmp = __go_image__ (ca, "cdata", img, "xdata", xdata, "ydata", ydata, |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
128 "cdatamapping", "direct", varargin {:}); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
129 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
130 ## 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
|
131 ## 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
|
132 ## 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
|
133 ## 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
|
134 ## 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
|
135 ## adjustment is necessary? |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
136 set (ca, "xlim", xlim, "ylim", ylim); |
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 if (ndims (img) == 3) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
139 if (isinteger (img)) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
140 c = class (img); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
141 mn = intmin (c); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
142 mx = intmax (c); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
143 set (ca, "clim", double ([mn, mx])); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
144 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
145 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
146 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
147 set (ca, "view", [0, 90]); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
148 |
10817
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
149 # Always reverse y-axis for images, even on existing plots |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
150 set (ca, "ydir", "reverse"); |
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
151 |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
152 if (nargout > 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
153 h = tmp; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
154 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
155 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
156 endfunction |