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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
1024
|
18 |
3381
|
19 ## -*- texinfo -*- |
4403
|
20 ## @deftypefn {Function File} {} imagesc (@var{A}) |
|
21 ## @deftypefnx {Function File} {} imagesc (@var{x}, @var{y}, @var{A}) |
|
22 ## @deftypefnx {Function File} {} imagesc (@dots{}, @var{limits}) |
|
23 ## @deftypefnx {Function File} { @var{B} = } imagesc (@dots{}) |
3651
|
24 ## Display a scaled version of the matrix @var{A} as a color image. The |
3373
|
25 ## matrix is scaled so that its entries are indices into the current |
6368
|
26 ## colormap. The scaled matrix is returned. If @var{limits} = [@var{lo}, @var{hi}] are |
4403
|
27 ## given, then that range maps into the full range of the colormap rather |
|
28 ## than the minimum and maximum values of @var{A}. |
3651
|
29 ## |
|
30 ## The axis values corresponding to the matrix elements are specified in |
4403
|
31 ## @var{x} and @var{y}, either as pairs giving the minimum and maximum |
|
32 ## values for the respective axes, or as values for each row and column |
6368
|
33 ## of the matrix @var{A}. |
5642
|
34 ## @seealso{image, imshow} |
3373
|
35 ## @end deftypefn |
559
|
36 |
3202
|
37 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
38 ## Created: July 1994 |
|
39 ## Adapted-By: jwe |
904
|
40 |
6368
|
41 function ret = imagesc (x, y, A, limits, DEPRECATEDZOOM) |
559
|
42 |
6368
|
43 ## Deprecated zoom. Remove this hunk of code if old zoom argument |
|
44 ## is outmoded. |
|
45 if ((nargin == 2 && isscalar (y)) |
|
46 || (nargin == 3 && (isscalar (y) || isscalar (A))) |
|
47 || (nargin == 4 && isscalar (limits)) |
|
48 || nargin == 5) |
|
49 warning ("image: zoom argument ignored -- use GUI features"); |
|
50 endif |
|
51 if (nargin == 5) |
|
52 if (isscalar (limits)) |
|
53 limits = DEPRECATEDZOOM; |
|
54 endif |
|
55 nargin = 4; |
|
56 endif |
|
57 if (nargin == 4 && isscalar (limits)) |
|
58 nargin = 3; |
|
59 endif |
|
60 if (nargin == 3 && (isscalar (y) || isscalar (A))) |
|
61 if (isscalar (y)) |
|
62 y = A; |
|
63 endif |
|
64 nargin = 2; |
|
65 endif |
|
66 if (nargin == 2 && isscalar (y)) |
|
67 nargin = 1; |
|
68 endif |
|
69 |
|
70 if (nargin < 1 || nargin > 4) |
6046
|
71 print_usage (); |
1024
|
72 elseif (nargin == 1) |
3651
|
73 A = x; |
6368
|
74 x = y = limits = []; |
3651
|
75 elseif (nargin == 2) |
|
76 A = x; |
6368
|
77 limits = y; |
|
78 x = y = []; |
|
79 elseif (nargin == 3 && !isscalar (x) && !isscalar (y) && !isscalar (A)) |
4403
|
80 limits = []; |
559
|
81 endif |
|
82 |
4403
|
83 ## use given limits or guess them from the matrix |
|
84 if (length (limits) == 2 && limits(2) >= limits(1)) |
|
85 minval = limits(1); |
|
86 maxval = limits(2); |
|
87 A(A < minval) = minval; |
|
88 A(A > maxval) = maxval; |
|
89 elseif (length (limits) == 0) |
|
90 maxval = max (A(:)); |
|
91 minval = min (A(:)); |
|
92 else |
|
93 error ("expected data limits to be [lo, hi]"); |
|
94 endif |
|
95 |
|
96 ## scale the limits to the range of the colormap |
559
|
97 if (maxval == minval) |
3882
|
98 B = ones (size (A)); |
559
|
99 else |
2303
|
100 ## Rescale values to between 1 and length (colormap) inclusive. |
3651
|
101 B = round ((A - minval) / (maxval - minval) * (rows (colormap) - 1)) + 1; |
559
|
102 endif |
|
103 |
4403
|
104 ## display or return the image |
3882
|
105 if (nargout == 0) |
6368
|
106 image (x, y, B); |
3882
|
107 else |
|
108 ret = B; |
|
109 endif |
559
|
110 |
|
111 endfunction |