Mercurial > octave
annotate scripts/image/image.m @ 24551:a7b6502b5cb5
doc: Add @ref from graphic object creation functions to list of graphic properties (bug #52816).
* uimenu.m, image.m, text.m, light.m, line.m, patch.m, surface.m, axes.m,
figure.m: Add @ref from graphic object creation functions to list of graphic
properties (bug #52816).
author | Rik <rik@octave.org> |
---|---|
date | Sun, 07 Jan 2018 21:11:39 -0800 |
parents | 194eb4bd202b |
children | 6652d3823428 |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1 ## Copyright (C) 1994-2017 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 6 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
7 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
8 ## (at your option) any later version. |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
13 ## GNU General Public License for more details. |
2313 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
1024 | 18 |
3381 | 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 | 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. |
24551
a7b6502b5cb5
doc: Add @ref from graphic object creation functions to list of graphic properties (bug #52816).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
56 ## |
a7b6502b5cb5
doc: Add @ref from graphic object creation functions to list of graphic properties (bug #52816).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
57 ## Graphic Properties: The full list of properties is documented at |
a7b6502b5cb5
doc: Add @ref from graphic object creation functions to list of graphic properties (bug #52816).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
58 ## @ref{Image Properties,,Image Properties}. |
11109
41d18f6342f9
remove image_viewer function
John W. Eaton <jwe@octave.org>
parents:
11090
diff
changeset
|
59 ## @seealso{imshow, imagesc, colormap} |
3373 | 60 ## @end deftypefn |
559 | 61 |
3202 | 62 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 63 ## Created: July 1994 |
64 ## Adapted-By: jwe | |
904 | 65 |
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
|
66 function h = image (varargin) |
7189 | 67 |
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
|
68 [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
|
69 |
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
|
70 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
|
71 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
72 do_new = true; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
73 if (nargin == 0) |
19324
68db8396c378
Make "image ()" use the default image cdata
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18899
diff
changeset
|
74 img = get (0, "defaultimagecdata"); |
7276 | 75 x = y = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18622
diff
changeset
|
76 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
|
77 ## Low-Level syntax |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
78 do_new = false; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
79 x = y = img = []; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
80 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
|
81 if (idx) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
82 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
|
83 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
|
84 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
85 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
|
86 if (idx) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
87 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
|
88 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
|
89 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
90 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
|
91 if (idx) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 elseif (nargin == 1 || chararg == 2) |
7276 | 96 img = varargin{1}; |
97 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
|
98 elseif (nargin == 2 || chararg == 3) |
7276 | 99 print_usage (); |
7189 | 100 else |
7276 | 101 x = varargin{1}; |
102 y = varargin{2}; | |
103 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
|
104 chararg = 4; |
15064
489736962e80
image.m: Don't accept complex image data (bug #36866)
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
105 endif |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
106 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
107 oldfig = []; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
108 if (! isempty (hax)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
109 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
|
110 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
111 unwind_protect |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
112 if (do_new) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
113 hax = newplot (hax); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
114 elseif (isempty (hax)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
115 hax = gca (); |
18821
87c3848cf3c0
Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents:
18683
diff
changeset
|
116 else |
87c3848cf3c0
Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents:
18683
diff
changeset
|
117 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
|
118 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
119 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
120 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
|
121 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
122 unwind_protect_cleanup |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
123 if (! isempty (oldfig)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
124 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
|
125 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
126 end_unwind_protect |
7276 | 127 |
7189 | 128 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
|
129 h = htmp; |
7189 | 130 endif |
131 | |
132 endfunction | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
133 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
134 ## Generic image creation. |
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 ## 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
|
137 ## @var{x} and @var{y}. |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
138 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
139 ## 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
|
140 ## Created: July 1994 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
141 ## Adapted-By: jwe |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
142 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
143 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
|
144 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
145 if (! isempty (img)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
146 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
147 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
|
148 xdata = []; |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
149 else |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
150 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
|
151 endif |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
152 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
153 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
|
154 ydata = []; |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
155 else |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
156 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
|
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 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
|
160 ## 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
|
161 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
|
162 dx = diff (x); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
163 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
|
164 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
|
165 dy = diff (y); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 "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
|
171 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
|
172 endif |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
173 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
174 endif # ! isempty (img) |
13980
bd2be36fd949
image.m: Warn if input coordinates are not linearly spaced.
Ben Abbott <bpabbott@mac.com>
parents:
13173
diff
changeset
|
175 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
176 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
|
177 ## 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
|
178 ## 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
|
179 ## 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
|
180 ## 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
|
181 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
|
182 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
|
183 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
|
184 endif |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
185 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
186 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
|
187 if (isinteger (img)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
188 cls = class (img); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
189 mn = intmin (cls); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
190 mx = intmax (cls); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
191 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
|
192 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
193 endif |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
194 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
195 endif # ! isempty (img) |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
196 |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
197 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
|
198 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
199 endif # do_new |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
200 |
19962
2e7497ff2535
image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
201 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
|
202 "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
|
203 |
2e7497ff2535
image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
204 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
|
205 && 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
|
206 ## 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
|
207 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
|
208 endif |
2e7497ff2535
image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
209 |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
210 endfunction |
10942
48a1812fcc3a
image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents:
10818
diff
changeset
|
211 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
212 |
10942
48a1812fcc3a
image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents:
10818
diff
changeset
|
213 %!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
|
214 %! 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
|
215 %! 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
|
216 %! 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
|
217 %! 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
|
218 %! 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
|
219 %! 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
|
220 %! 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
|
221 %! 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
|
222 %! 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
|
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 %! 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
|
226 %! 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
|
227 %! 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
|
228 %! 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
|
229 %! 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
|
230 %! 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
|
231 %! title ("image (-x, -y, img)"); |
10942
48a1812fcc3a
image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents:
10818
diff
changeset
|
232 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22488
diff
changeset
|
233 ## test hidden properties x/ydatamode |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
234 %!test <*42121> |
18899
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
235 %! 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
|
236 %! unwind_protect |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
237 %! 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
|
238 %! 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
|
239 %! 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
|
240 %! assert (get (hi, "xdata"), [1 nx]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
241 %! assert (get (hi, "ydata"), [1 ny]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
242 %! 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
|
243 %! assert (get (hi, "xdata"), [1 nx/2]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
244 %! 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
|
245 %! |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
246 %! 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
|
247 %! 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
|
248 %! set (hi, "cdata", cdata); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
249 %! assert (get (hi, "xdata"), [10 100]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
250 %! 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
|
251 %! |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
252 %! set (hi, "ydata", []); # ydatamode is now auto |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
253 %! 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
|
254 %! assert (get (hi, "xdata"), [10 100]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
255 %! 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
|
256 %! unwind_protect_cleanup |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
257 %! close (hf); |
18899
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
258 %! end_unwind_protect |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
259 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
260 ## FIXME: Need %!tests for linear |