comparison scripts/image/imagesc.m @ 4403:f52b3f1a9399

[project @ 2003-05-01 19:28:11 by jwe]
author jwe
date Thu, 01 May 2003 19:28:11 +0000
parents c8c1ead8474f
children c08cb1098afc
comparison
equal deleted inserted replaced
4402:868983234164 4403:f52b3f1a9399
16 ## along with Octave; see the file COPYING. If not, write to the Free 16 ## along with Octave; see the file COPYING. If not, write to the Free
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA 17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
18 ## 02111-1307, USA. 18 ## 02111-1307, USA.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} imagesc (@var{A}, @var{zoom}) 21 ## @deftypefn {Function File} {} imagesc (@var{A})
22 ## @deftypefnx {Function File} {} imagesc (@var{x}, @var{y}, @var{A}, @var{zoom}) 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{})
23 ## Display a scaled version of the matrix @var{A} as a color image. The 26 ## Display a scaled version of the matrix @var{A} as a color image. The
24 ## matrix is scaled so that its entries are indices into the current 27 ## matrix is scaled so that its entries are indices into the current
25 ## colormap. The scaled matrix is returned. If @var{zoom} is omitted, a 28 ## colormap. The scaled matrix is returned. If @var{zoom} is omitted, a
26 ## comfortable size is chosen. 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}.
27 ## 32 ##
28 ## The axis values corresponding to the matrix elements are specified in 33 ## The axis values corresponding to the matrix elements are specified in
29 ## @var{x} and @var{y}. At present they are ignored. 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.
30 ## @end deftypefn 37 ## @end deftypefn
31 ## @seealso{image and imshow} 38 ## @seealso{image and imshow}
32 39
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us> 40 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
34 ## Created: July 1994 41 ## Created: July 1994
35 ## Adapted-By: jwe 42 ## Adapted-By: jwe
36 43
37 function ret = imagesc (x, y, A, zoom) 44 function ret = imagesc (x, y, A, zoom, limits)
38 45
39 if (nargin < 1 || nargin > 4) 46 if (nargin < 1 || nargin > 5)
40 usage ("imagesc (matrix, zoom) or imagesc (x, y, matrix, zoom)"); 47 usage ("B = imagesc ([x, y,] matrix [,limits] [,zoom])");
41 elseif (nargin == 1) 48 elseif (nargin == 1)
42 A = x; 49 A = x;
43 zoom = []; 50 zoom = x = y = limits = [];
44 x = y = [];
45 elseif (nargin == 2) 51 elseif (nargin == 2)
46 A = x; 52 A = x;
47 zoom = y; 53 zoom = y;
48 x = y = []; 54 x = y = limits = [];
49 elseif (nargin == 3) 55 elseif (nargin == 3)
50 zoom = []; 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 = [];
51 endif 63 endif
52 64
53 maxval = max (A(:)); 65 ## correct for zoom, limits parameter order
54 minval = min (A(:)); 66 if (length (zoom) == 2)
67 swap = limits;
68 limits = zoom;
69 zoom = swap;
70 endif
55 71
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
56 if (maxval == minval) 86 if (maxval == minval)
57 B = ones (size (A)); 87 B = ones (size (A));
58 else 88 else
59 ## Rescale values to between 1 and length (colormap) inclusive. 89 ## Rescale values to between 1 and length (colormap) inclusive.
60 B = round ((A - minval) / (maxval - minval) * (rows (colormap) - 1)) + 1; 90 B = round ((A - minval) / (maxval - minval) * (rows (colormap) - 1)) + 1;
61 endif 91 endif
62 92
93 ## display or return the image
63 if (nargout == 0) 94 if (nargout == 0)
64 image (x, y, B, zoom); 95 image (x, y, B, zoom);
65 else 96 else
66 ret = B; 97 ret = B;
67 endif 98 endif