]> Creatis software - CreaPhase.git/blob - octave_packages/m/image/imagesc.m
update packages
[CreaPhase.git] / octave_packages / m / image / imagesc.m
1 ## Copyright (C) 1994-2012 John W. Eaton
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 3 of the License, or (at
8 ## your option) 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, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
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} {} imagesc (@var{h}, @dots{})
24 ## @deftypefnx {Function File} {@var{h} =} imagesc (@dots{})
25 ## Display a scaled version of the matrix @var{A} as a color image.  The
26 ## colormap is scaled so that the entries of the matrix occupy the entire
27 ## colormap.  If @var{limits} = [@var{lo}, @var{hi}] are given, then that
28 ## range is set to the 'clim' of the current axes.
29 ##
30 ## The axis values corresponding to the matrix elements are specified in
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
33 ## of the matrix @var{A}.
34 ##
35 ## The optional return value @var{h} is a graphics handle to the image.
36 ## @seealso{image, imshow, caxis}
37 ## @end deftypefn
38
39 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
40 ## Created: July 1994
41 ## Adapted-By: jwe
42
43 function retval = imagesc (varargin)
44
45   if (nargin < 1)
46     print_usage ();
47   elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
48     h = varargin{1};
49     if (! strcmp (get (h, "type"), "axes"))
50       error ("imagesc: expecting first argument to be an axes object");
51     endif
52     oldh = gca ();
53     unwind_protect
54       axes (h);
55       tmp = __imagesc__ (h, varargin{2:end});
56     unwind_protect_cleanup
57       axes (oldh);
58     end_unwind_protect
59   else
60     tmp = __imagesc__ (gca (), varargin{:});
61   endif
62
63   if (nargout > 0)
64     retval = tmp;
65   endif
66
67 endfunction
68
69 function ret = __imagesc__ (ax, x, y, A, limits, DEPRECATEDZOOM)
70
71   ## Deprecated zoom.  Remove this hunk of code if old zoom argument
72   ## is outmoded.
73   if ((nargin == 3 && isscalar (y))
74       || (nargin == 4 && (isscalar (y) || isscalar (A)))
75       || (nargin == 5 && isscalar (limits))
76       || nargin == 6)
77     warning ("image: zoom argument ignored -- use GUI features");
78   endif
79   if (nargin == 6)
80     if (isscalar (limits))
81       limits = DEPRECATEDZOOM;
82     endif
83     nargin = 5;
84   endif
85   if (nargin == 5 && isscalar (limits))
86     nargin = 4;
87   endif
88   if (nargin == 4 && (isscalar (y) || isscalar (A)))
89     if (isscalar (y))
90       y = A;
91     endif
92     nargin = 3;
93   endif
94   if (nargin == 3 && isscalar (y))
95     nargin = 2;
96   endif
97
98   if (nargin < 2 || nargin > 5)
99     print_usage ();
100   elseif (nargin == 2)
101     A = x;
102     x = y = limits = [];
103   elseif (nargin == 3)
104     A = x;
105     limits = y;
106     x = y = [];
107   elseif (nargin == 4 && ! isscalar (x) && ! isscalar (y) && ! isscalar (A))
108     limits = [];
109   endif
110
111   ret = image (ax, x, y, A);
112   set (ret, "cdatamapping", "scaled");
113
114   ## use given limits or guess them from the matrix
115   if (length (limits) == 2 && limits(2) >= limits(1))
116     set (ax, "clim", limits);
117   elseif (! isempty (limits))
118     error ("imagesc: expected data LIMITS to be [lo, hi]");
119   endif
120
121 endfunction