annotate scripts/image/image.m @ 22489:93ea313301f9

test: Add bug ids (<#####>) to BIST tests. * bsxfun.cc, cellfun.cc, conv2.cc, data.cc, ellipj.cc, error.cc, file-io.cc, graphics.cc, hash.cc, mappers.cc, max.cc, rand.cc, regexp.cc, symtab.cc, chol.cc, gzip.cc, symbfact.cc, ov-cx-diag.cc, ov-fcn-handle.cc, ov-java.cc, Sparse.cc, accumarray.m, bitset.m, fieldnames.m, inputParser.m, interp2.m, interpft.m, num2str.m, postpad.m, prepad.m, rat.m, rectint.m, image.m, imread.m, imwrite.m, importdata.m, strread.m, textread.m, orderfields.m, qp.m, axis.m, legend.m, hist.m, residue.m, setdiff.m, fftshift.m, ifftshift.m, nthroot.m, magic.m, median.m, quantile.m, base2dec.m, strsplit.m, datestr.m, datevec.m: test: Add bug ids (<#####>) to BIST tests.
author Rik <rik@octave.org>
date Wed, 14 Sep 2016 16:05:16 -0700
parents a666e3ee6af8
children 3a2b891d0b33 3ac9f9ecfae5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
1 ## Copyright (C) 1994-2016 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 -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
20 ## @deftypefn {} {} image (@var{img})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
21 ## @deftypefnx {} {} image (@var{x}, @var{y}, @var{img})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
22 ## @deftypefnx {} {} image (@dots{}, "@var{prop}", @var{val}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
23 ## @deftypefnx {} {} image ("@var{prop1}", @var{val1}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
24 ## @deftypefnx {} {@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.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19962
diff changeset
28 ##
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
29 ## @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
30 ## 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
31 ## @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
32 ## 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
33 ## 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
34 ## last elements will be used to determine the axis limits.
10817
d9147775da54 image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
35 ##
17689
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
36 ## 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
37 ## 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
38 ##
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
39 ## 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
40 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
41 ## 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
42 ## 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
43 ## 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
44 ## 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
45 ## @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
46 ## 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
47 ## 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
48 ## 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
49 ##
17689
dd8db3f1c1da doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents: 17648
diff changeset
50 ## 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
51 ## 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
52 ## 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
53 ## 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
54 ## 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
55 ## and inserts it in the current axes.
11109
41d18f6342f9 remove image_viewer function
John W. Eaton <jwe@octave.org>
parents: 11090
diff changeset
56 ## @seealso{imshow, imagesc, colormap}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
57 ## @end deftypefn
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
58
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 2847
diff changeset
59 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
60 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
61 ## Adapted-By: jwe
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 686
diff changeset
62
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
63 function h = image (varargin)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
64
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
65 [hax, varargin, nargin] = __plt_get_axis_arg__ ("image", varargin{:});
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18622
diff changeset
66
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
67 chararg = find (cellfun ("isclass", varargin, "char"), 1, "first");
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18622
diff changeset
68
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
69 do_new = true;
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
70 if (nargin == 0)
19324
68db8396c378 Make "image ()" use the default image cdata
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18899
diff changeset
71 img = get (0, "defaultimagecdata");
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
72 x = y = [];
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18622
diff changeset
73 elseif (chararg == 1)
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
74 ## Low-Level syntax
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
75 do_new = false;
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
76 x = y = img = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
77 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
78 if (idx)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
79 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
80 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
81 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
82 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
83 if (idx)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
84 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
85 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
86 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
87 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
88 if (idx)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
89 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
90 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
91 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
92 elseif (nargin == 1 || chararg == 2)
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
93 img = varargin{1};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
94 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
95 elseif (nargin == 2 || chararg == 3)
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
96 print_usage ();
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
97 else
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
98 x = varargin{1};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
99 y = varargin{2};
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
100 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
101 chararg = 4;
15064
489736962e80 image.m: Don't accept complex image data (bug #36866)
Rik <rik@octave.org>
parents: 14872
diff changeset
102 endif
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
103
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
104 oldfig = [];
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
105 if (! isempty (hax))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
106 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
107 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
108 unwind_protect
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
109 if (do_new)
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
110 hax = newplot (hax);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
111 elseif (isempty (hax))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
112 hax = gca ();
18821
87c3848cf3c0 Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents: 18683
diff changeset
113 else
87c3848cf3c0 Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents: 18683
diff changeset
114 hax = hax(1);
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
115 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
116
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
117 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
118
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
119 unwind_protect_cleanup
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
120 if (! isempty (oldfig))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
121 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
122 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
123 end_unwind_protect
7276
1e8e64d71e34 [project @ 2007-12-10 20:09:59 by jwe]
jwe
parents: 7208
diff changeset
124
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
125 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
126 h = htmp;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
127 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
128
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7074
diff changeset
129 endfunction
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
130
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
131 ## Generic image creation.
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
132 ##
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
133 ## The axis values corresponding to the matrix elements are specified in
22488
a666e3ee6af8 Require gnuplot 4.4 as mininimum supported version.
Rik <rik@octave.org>
parents: 22366
diff changeset
134 ## @var{x} and @var{y}.
9899
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
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
142 if (! isempty (img))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
143
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
144 if (isempty (x))
18899
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
145 xdata = [];
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
146 else
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
147 xdata = x([1, end])(:).'; # (:).' is a hack to guarantee row vector
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
148 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
149
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
150 if (isempty (y))
18899
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
151 ydata = [];
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
152 else
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
153 ydata = y([1, end])(:).';
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
154 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
155
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
156 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
157 ## 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
158 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
159 dx = diff (x);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
160 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
161 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
162 dy = diff (y);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
163 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
164 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
165 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
166 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
167 "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
168 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
169 endif
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
170
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
171 endif # ! isempty (img)
13980
bd2be36fd949 image.m: Warn if input coordinates are not linearly spaced.
Ben Abbott <bpabbott@mac.com>
parents: 13173
diff changeset
172
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
173 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
174 ## Set axis properties for new images
19962
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
175 ## NOTE: Do this before calling __go_image__ so that image is not drawn
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
176 ## once with default auto-scale axis limits and then a second time
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
177 ## with tight axis limits.
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
178 if (! isempty (img))
19962
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
179 if (isempty (get (hax, "children")))
18622
3283ce934648 Set only 'axis tight' for image functions and Matlab compatibility (bug #42043, bug #41886)
Rik <rik@octave.org>
parents: 18524
diff changeset
180 axis (hax, "tight");
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
181 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
182
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
183 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
184 if (isinteger (img))
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
185 cls = class (img);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
186 mn = intmin (cls);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
187 mx = intmax (cls);
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
188 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
189 endif
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
190 endif
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
191
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
192 endif # ! isempty (img)
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
193
22366
837df5db5710 Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents: 22323
diff changeset
194 set (hax, "view", [0, 90], "ydir", "reverse", "layer", "top", "box", "on");
10817
d9147775da54 image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
195
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
196 endif # do_new
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
197
19962
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
198 h = __go_image__ (hax, "cdata", img, "xdata", xdata, "ydata", ydata,
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
199 "cdatamapping", "direct", varargin{:});
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
200
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
201 if (do_new && ! ishold (hax) && ! isempty (img)
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
202 && isscalar (get (hax, "children")))
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
203 ## Re-scale axis limits for an image in a new figure or axis.
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
204 axis (hax, "tight");
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
205 endif
2e7497ff2535 image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents: 19697
diff changeset
206
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
207 endfunction
10942
48a1812fcc3a image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents: 10818
diff changeset
208
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
209
10942
48a1812fcc3a image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents: 10818
diff changeset
210 %!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
211 %! 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
212 %! 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
213 %! 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
214 %! 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
215 %! 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
216 %! 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
217 %! 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
218 %! 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
219 %! 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
220 %! 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
221 %! 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
222 %! 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
223 %! 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
224 %! 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
225 %! 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
226 %! 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
227 %! 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
228 %! title ("image (-x, -y, img)");
10942
48a1812fcc3a image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents: 10818
diff changeset
229
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22488
diff changeset
230 ## test hidden properties x/ydatamode
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22488
diff changeset
231 %!test <42121>
18899
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
232 %! hf = figure ("visible", "off");
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
233 %! unwind_protect
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
234 %! nx = 64; ny = 64;
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
235 %! cdata = rand (ny, nx)*127;
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
236 %! hi = image (cdata); # x/ydatamode is auto
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
237 %! assert (get (hi, "xdata"), [1 nx]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
238 %! assert (get (hi, "ydata"), [1 ny]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
239 %! set (hi, "cdata", cdata(1:2:end, 1:2:end));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
240 %! assert (get (hi, "xdata"), [1 nx/2]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
241 %! assert (get (hi, "ydata"), [1 ny/2]);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
242 %!
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
243 %! set (hi, "xdata", [10 100]); # xdatamode is now manual
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
244 %! set (hi, "ydata", [10 1000]); # ydatamode is now manual
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
245 %! set (hi, "cdata", cdata);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
246 %! assert (get (hi, "xdata"), [10 100]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
247 %! assert (get (hi, "ydata"), [10 1000]);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
248 %!
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
249 %! set (hi, "ydata", []); # ydatamode is now auto
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
250 %! set (hi, "cdata", cdata(1:2:end, 1:2:end));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
251 %! assert (get (hi, "xdata"), [10 100]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
252 %! assert (get (hi, "ydata"), [1 ny/2]);
18899
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
253 %! unwind_protect_cleanup
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
254 %! close (hf);
18899
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
255 %! end_unwind_protect
3d9e503aea2c Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18821
diff changeset
256
17692
38cf56b77274 Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents: 17689
diff changeset
257 ## FIXME: Need %!tests for linear