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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1024
|
19 |
3381
|
20 ## -*- texinfo -*- |
4403
|
21 ## @deftypefn {Function File} {} imagesc (@var{A}) |
|
22 ## @deftypefnx {Function File} {} imagesc (@var{x}, @var{y}, @var{A}) |
|
23 ## @deftypefnx {Function File} {} imagesc (@dots{}, @var{zoom}) |
|
24 ## @deftypefnx {Function File} {} imagesc (@dots{}, @var{limits}) |
|
25 ## @deftypefnx {Function File} { @var{B} = } imagesc (@dots{}) |
3651
|
26 ## Display a scaled version of the matrix @var{A} as a color image. The |
3373
|
27 ## matrix is scaled so that its entries are indices into the current |
|
28 ## colormap. The scaled matrix is returned. If @var{zoom} is omitted, a |
4403
|
29 ## comfortable size is chosen. If @var{limits} = [@var{lo}, @var{hi}] are |
|
30 ## given, then that range maps into the full range of the colormap rather |
|
31 ## than the minimum and maximum values of @var{A}. |
3651
|
32 ## |
|
33 ## The axis values corresponding to the matrix elements are specified in |
4403
|
34 ## @var{x} and @var{y}, either as pairs giving the minimum and maximum |
|
35 ## values for the respective axes, or as values for each row and column |
|
36 ## of the matrix @var{A}. At present they are ignored. |
5642
|
37 ## @seealso{image, imshow} |
3373
|
38 ## @end deftypefn |
559
|
39 |
3202
|
40 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
41 ## Created: July 1994 |
|
42 ## Adapted-By: jwe |
904
|
43 |
4403
|
44 function ret = imagesc (x, y, A, zoom, limits) |
559
|
45 |
4403
|
46 if (nargin < 1 || nargin > 5) |
6046
|
47 print_usage (); |
1024
|
48 elseif (nargin == 1) |
3651
|
49 A = x; |
4403
|
50 zoom = x = y = limits = []; |
3651
|
51 elseif (nargin == 2) |
|
52 A = x; |
|
53 zoom = y; |
4403
|
54 x = y = limits = []; |
3651
|
55 elseif (nargin == 3) |
4403
|
56 ## Assume imagesc(x,y,A) for compatibility. It |
|
57 ## could also be imagesc(A,limits,zoom), but if A is |
|
58 ## a 1x2 vector, this is equivalent to imagesc(x,y,A) |
|
59 ## for scalar A so we won't try to guess. |
|
60 zoom = limits = []; |
|
61 elseif (nargin == 4) |
|
62 limits = []; |
559
|
63 endif |
|
64 |
4403
|
65 ## correct for zoom, limits parameter order |
|
66 if (length (zoom) == 2) |
|
67 swap = limits; |
|
68 limits = zoom; |
|
69 zoom = swap; |
|
70 endif |
1024
|
71 |
4403
|
72 ## use given limits or guess them from the matrix |
|
73 if (length (limits) == 2 && limits(2) >= limits(1)) |
|
74 minval = limits(1); |
|
75 maxval = limits(2); |
|
76 A(A < minval) = minval; |
|
77 A(A > maxval) = maxval; |
|
78 elseif (length (limits) == 0) |
|
79 maxval = max (A(:)); |
|
80 minval = min (A(:)); |
|
81 else |
|
82 error ("expected data limits to be [lo, hi]"); |
|
83 endif |
|
84 |
|
85 ## scale the limits to the range of the colormap |
559
|
86 if (maxval == minval) |
3882
|
87 B = ones (size (A)); |
559
|
88 else |
2303
|
89 ## Rescale values to between 1 and length (colormap) inclusive. |
3651
|
90 B = round ((A - minval) / (maxval - minval) * (rows (colormap) - 1)) + 1; |
559
|
91 endif |
|
92 |
4403
|
93 ## display or return the image |
3882
|
94 if (nargout == 0) |
|
95 image (x, y, B, zoom); |
|
96 else |
|
97 ret = B; |
|
98 endif |
559
|
99 |
|
100 endfunction |