annotate scripts/image/image.m @ 17692:38cf56b77274

Overhaul image, imagesc to use newplot and support low-level invocation form. * scripts/image/image.m: New variable do_new indicates high-level calling form. For high-level invocation, call newplot before __img__. Correct linearity check if vectors are reversed (high-to-low values). Only apply image properties to axes if doing a high-level invocation. * scripts/image/imagesc.m: New variable do_new indicates high-level calling form. Delete subfunction __imagesc__ and incorporate minimal amount of code into imagesc. Only apply climits for high-level invocation.
author Rik <rik@octave.org>
date Fri, 18 Oct 2013 16:27:44 -0700
parents dd8db3f1c1da
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14001
diff changeset
1 ## Copyright (C) 1994-2012 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6368
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
18
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10704
diff changeset
20 ## @deftypefn {Function File} {} image (@var{img})
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6164
diff changeset
21 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{img})
17689
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
22 ## @deftypefnx {Function File} {} image (@dots{}, "@var{prop}", @var{val}, @dots{})
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
23 ## @deftypefnx {Function File} {} image ("@var{prop1}", @var{val1}, @dots{})
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13993
diff changeset
24 ## @deftypefnx {Function File} {@var{h} =} image (@dots{})
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
25 ## Display a matrix as an indexed color image.
3651
c2305b99fbd7 [project @ 2000-03-31 07:12:29 by jwe]
jwe
parents: 3457
diff changeset
26 ##
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
27 ## The elements of @var{img} are indices into the current colormap.
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
28 ## @var{x} and @var{y} are optional 2-element vectors, @w{@code{[min, max]}},
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
29 ## which specify the range for the axis labels. If a range is specified as
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
30 ## @w{@code{[max, min]}} then the image will be reversed along that axis. For
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
31 ## convenience, @var{x} and @var{y} may be specified as N-element vectors
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
32 ## matching the length of the data in @var{img}. However, only the first and
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
33 ## last elements will be used to determine the axis limits.
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
34 ## @strong{Warning:} @var{x} and @var{y} are ignored when using gnuplot 4.0
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
35 ## or earlier.
10817
d9147775da54 image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
36 ##
17689
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
37 ## Multiple property/value pairs may be specified for the image object, but
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
38 ## they must appear in pairs.
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
39 ##
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
40 ## The optional return value @var{h} is a graphics handle to the image.
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
41 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
42 ## Implementation Note: The origin (0, 0) for images is located in the
10817
d9147775da54 image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
43 ## 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
44 ## 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
45 ## and then reversing the direction of the y-axis by setting the
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17038
diff changeset
46 ## @code{ydir} property to @qcode{"reverse"}. This has implications whenever
10817
d9147775da54 image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
47 ## 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
48 ## solution is to display the image and then plot the reversed ydata
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
49 ## using, for example, @code{flipud (ydata)}.
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13993
diff changeset
50 ##
17689
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
51 ## Calling Forms: The @code{image} function can be called in two forms:
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
52 ## High-Level and Low-Level. When invoked with normal options, the High-Level
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
53 ## form is used which first calls @code{newplot} to prepare the graphic figure
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
54 ## and axes. When the only inputs to @code{image} are property/value pairs
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
55 ## the Low-Level form is used which creates a new instance of an image object
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
56 ## and inserts it in the current axes.
11109
41d18f6342f9 remove image_viewer function
John W. Eaton <jwe@octave.org>
parents: 11090
diff changeset
57 ## @seealso{imshow, imagesc, colormap}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
58 ## @end deftypefn
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
59
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 2847
diff changeset
60 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
61 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
62 ## Adapted-By: jwe
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 686
diff changeset
63
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
64 function h = image (varargin)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
65
17038
db90efd8f32b image.m: Update to use new __plt_get_axis_arg__ without using "axes" and "newplot" function.
Rik <rik@octave.org>
parents: 15764
diff changeset
66 [hax, varargin, nargin] = __plt_get_axis_arg__ ("image", varargin{:});
db90efd8f32b image.m: Update to use new __plt_get_axis_arg__ without using "axes" and "newplot" function.
Rik <rik@octave.org>
parents: 15764
diff changeset
67
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
68 chararg = find (cellfun ("isclass", varargin, "char"), 1, "first");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
69
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
70 do_new = true;
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
71 if (nargin == 0)
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10433
diff changeset
72 img = imread ("default.img");
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
73 x = y = [];
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
74 elseif (chararg == 1)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
75 ## Low-Level syntax
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
76 do_new = false;
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
77 x = y = img = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
78 idx = find (strcmpi (varargin, "cdata"), 1);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
79 if (idx)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
80 img = varargin{idx+1};
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
81 varargin(idx:idx+1) = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
82 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
83 idx = find (strcmpi (varargin, "xdata"), 1);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
84 if (idx)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
85 x = varargin{idx+1};
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
86 varargin(idx:idx+1) = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
87 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
88 idx = find (strcmpi (varargin, "ydata"), 1);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
89 if (idx)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
90 y = varargin{idx+1};
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
91 varargin(idx:idx+1) = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
92 endif
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
93 elseif (nargin == 1 || chararg == 2)
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
94 img = varargin{1};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
95 x = y = [];
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
96 elseif (nargin == 2 || chararg == 3)
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
97 print_usage ();
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
98 else
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
99 x = varargin{1};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
100 y = varargin{2};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
101 img = varargin{3};
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
102 chararg = 4;
15064
489736962e80 image.m: Don't accept complex image data (bug #36866)
Rik <rik@octave.org>
parents: 14872
diff changeset
103 endif
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
104
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
105 oldfig = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
106 if (! isempty (hax))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
107 oldfig = get (0, "currentfigure");
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
108 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
109 unwind_protect
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
110 if (do_new)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
111 hax = newplot (hax);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
112 elseif (isempty (hax))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
113 hax = gca ();
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
114 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
115
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
116 htmp = __img__ (hax, do_new, x, y, img, varargin{chararg:end});
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
117
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
118 unwind_protect_cleanup
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
119 if (! isempty (oldfig))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
120 set (0, "currentfigure", oldfig);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
121 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
122 end_unwind_protect
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
123
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
124 if (nargout > 0)
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
125 h = htmp;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
126 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
127
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
128 endfunction
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 ## Generic image creation.
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
131 ##
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
132 ## The axis values corresponding to the matrix elements are specified in
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
133 ## @var{x} and @var{y}. If you're not using gnuplot 4.2 or later, these
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
134 ## variables are ignored.
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
135
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
136 ## 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
137 ## Created: July 1994
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
138 ## Adapted-By: jwe
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
139
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
140 function h = __img__ (hax, do_new, x, y, img, varargin)
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
141
15764
0a27a0e157a6 Temporary fix for display of indexed images of integer class.
Rik <rik@octave.org>
parents: 15683
diff changeset
142 ## FIXME: Hack for integer formats which use zero-based indexing
0a27a0e157a6 Temporary fix for display of indexed images of integer class.
Rik <rik@octave.org>
parents: 15683
diff changeset
143 ## Hack favors correctness of display over size of image in memory.
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
144 ## True fix must be done in C++ code for renderer.
15764
0a27a0e157a6 Temporary fix for display of indexed images of integer class.
Rik <rik@octave.org>
parents: 15683
diff changeset
145 if (ndims (img) == 2 && (isinteger (img) || islogical (img)))
0a27a0e157a6 Temporary fix for display of indexed images of integer class.
Rik <rik@octave.org>
parents: 15683
diff changeset
146 img = single (img) + 1;
0a27a0e157a6 Temporary fix for display of indexed images of integer class.
Rik <rik@octave.org>
parents: 15683
diff changeset
147 endif
0a27a0e157a6 Temporary fix for display of indexed images of integer class.
Rik <rik@octave.org>
parents: 15683
diff changeset
148
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
149 if (! isempty (img))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
150
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
151 if (isempty (x))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
152 x = [1, columns(img)];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
153 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
154
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
155 if (isempty (y))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
156 y = [1, rows(img)];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
157 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
158
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
159 xdata = x([1, end]);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
160 ydata = y([1, end]);
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
161
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
162 if (numel (x) > 2 && numel (y) > 2)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
163 ## Test data for non-linear spacing which is unsupported
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
164 tol = .01; # 1% tolerance. FIXME: this value was chosen without thought.
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
165 dx = diff (x);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
166 dxmean = (max (x) - min (x)) / (numel (x) - 1);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
167 dx = abs ((abs (dx) - dxmean) / dxmean);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
168 dy = diff (y);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
169 dymean = (max (y) - min (y)) / (numel (y) - 1);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
170 dy = abs ((abs (dy) - dymean) / dymean);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
171 if (any (dx > tol) || any (dy > tol))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
172 warning (["image: non-linear X, Y data is ignored. " ...
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
173 "IMG will be shown with linear mapping"]);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
174 endif
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
175 endif
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
176
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
177 endif # ! isempty (img)
13980
bd2be36fd949 image.m: Warn if input coordinates are not linearly spaced.
Ben Abbott <bpabbott@mac.com>
parents: 13173
diff changeset
178
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
179 h = __go_image__ (hax, "cdata", img, "xdata", xdata, "ydata", ydata,
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
180 "cdatamapping", "direct", varargin{:});
11076
b748b86cb8c1 fix images with width or height of 1
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10952
diff changeset
181
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
182 if (do_new && ! ishold (hax))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
183 ## Set axis properties for new images
11090
2adf4736dafa Do not store flipped image property values when x/ydata descends.
Ben Abbott <bpabbott@mac.com>
parents: 11080
diff changeset
184
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
185 if (! isempty (img))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
186 px = __image_pixel_size__ (h);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
187
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
188 if (xdata(2) < xdata(1))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
189 xdata = fliplr (xdata);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
190 elseif (xdata(2) == xdata(1))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
191 xdata = xdata(1) + [0, columns(img)-1];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
192 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
193 if (ydata(2) < ydata(1))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
194 ydata = fliplr (ydata);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
195 elseif (ydata(2) == ydata(1))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
196 ydata = ydata(1) + [0, rows(img)-1];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
197 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
198 xlim = xdata + [-px(1), px(1)];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
199 ylim = ydata + [-px(2), px(2)];
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
200
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
201 ## FIXME -- how can we do this and also get the {x,y}limmode
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
202 ## properties to remain "auto"? I suppose this adjustment should
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
203 ## happen automatically in axes::update_axis_limits instead of
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
204 ## explicitly setting the values here. But then what information is
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
205 ## available to axes::update_axis_limits to determine that the
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
206 ## adjustment is necessary?
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
207 set (hax, "xlim", xlim, "ylim", ylim);
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
208
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
209 if (ndims (img) == 3)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
210 if (isinteger (img))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
211 cls = class (img);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
212 mn = intmin (cls);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
213 mx = intmax (cls);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
214 set (hax, "clim", double ([mn, mx]));
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
215 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
216 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
217
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
218 endif # ! isempty (img)
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
219
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
220 set (hax, "view", [0, 90], "ydir", "reverse", "layer", "bottom");
10817
d9147775da54 image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
221
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
222 endif # do_new
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
223
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
224 endfunction
10942
48a1812fcc3a image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents: 10818
diff changeset
225
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
226
10942
48a1812fcc3a image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents: 10818
diff changeset
227 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
228 %! clf;
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
229 %! colormap (jet (21));
11080
36ceff79607b image.m: Allow x/ydata to imply a flip of the image. Modify demos.
Ben Abbott <bpabbott@mac.com>
parents: 11076
diff changeset
230 %! img = 1 ./ hilb (11);
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
231 %! x = y = -5:5;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
232 %! subplot (2,2,1);
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
233 %! h = image (x, y, img);
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
234 %! ylabel ("limits = [-5.5, 5.5]");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 15202
diff changeset
235 %! title ("image (x, y, img)");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
236 %! subplot (2,2,2);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
237 %! h = image (-x, y, img);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
238 %! title ("image (-x, y, img)");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
239 %! subplot (2,2,3);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
240 %! h = image (x, -y, img);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
241 %! title ("image (x, -y, img)");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
242 %! ylabel ("limits = [-5.5, 5.5]");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
243 %! subplot (2,2,4);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
244 %! h = image (-x, -y, img);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
245 %! title ("image (-x, -y, img)");
10942
48a1812fcc3a image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents: 10818
diff changeset
246
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
247 ## FIXME: Need %!tests for linear