Mercurial > octave
annotate scripts/image/image.m @ 33596:96a203bc7e17 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Fri, 17 May 2024 22:49:58 -0400 |
parents | 2edd93f097ff |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 1994-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
2313 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 11 ## 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
|
12 ## 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
|
13 ## (at your option) any later version. |
2313 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
18 ## GNU General Public License for more details. |
2313 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## 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
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
1024 | 25 |
3381 | 26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
27 ## @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
|
28 ## @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
|
29 ## @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
|
30 ## @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
|
31 ## @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
|
32 ## Display a matrix as an indexed color image. |
3651 | 33 ## |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
34 ## 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
|
35 ## |
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
|
36 ## @var{x} and @var{y} are optional 2-element vectors, @w{@code{[min, max]}}, |
25856
9578af67a0d4
Document that image x/ydata indicate the centers of corner pixels (bug #54610).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
37 ## which specify the coordinates of the centers of the corner pixels. |
9578af67a0d4
Document that image x/ydata indicate the centers of corner pixels (bug #54610).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
38 ## If a range is specified as @w{@code{[max, min]}} then the image will be |
9578af67a0d4
Document that image x/ydata indicate the centers of corner pixels (bug #54610).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
39 ## reversed along that axis. For convenience, @var{x} and @var{y} may be |
9578af67a0d4
Document that image x/ydata indicate the centers of corner pixels (bug #54610).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
40 ## specified as N-element vectors matching the length of the data in @var{img}. |
9578af67a0d4
Document that image x/ydata indicate the centers of corner pixels (bug #54610).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
41 ## However, only the first and last elements will be used to determine the axis |
9578af67a0d4
Document that image x/ydata indicate the centers of corner pixels (bug #54610).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
42 ## limits. |
10817
d9147775da54
image.m: Always reverse 'ydir' property when displaying images.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
43 ## |
17689
dd8db3f1c1da
doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents:
17648
diff
changeset
|
44 ## 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
|
45 ## 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
|
46 ## |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
47 ## 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
|
48 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
49 ## 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
|
50 ## 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
|
51 ## 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
|
52 ## 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
|
53 ## @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
|
54 ## 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
|
55 ## 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
|
56 ## 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
|
57 ## |
17689
dd8db3f1c1da
doc: Add information about High-Level/Low-Level calling forms for image, imagesc.
Rik <rik@octave.org>
parents:
17648
diff
changeset
|
58 ## 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
|
59 ## 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
|
60 ## 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
|
61 ## 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
|
62 ## 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
|
63 ## 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
|
64 ## |
a7b6502b5cb5
doc: Add @ref from graphic object creation functions to list of graphic properties (bug #52816).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
65 ## Graphic Properties: The full list of properties is documented at |
28093
05c1217d0dae
doc: Create better looking cross references in Info format (bug #57845).
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
66 ## @ref{Image Properties}. |
11109
41d18f6342f9
remove image_viewer function
John W. Eaton <jwe@octave.org>
parents:
11090
diff
changeset
|
67 ## @seealso{imshow, imagesc, colormap} |
3373 | 68 ## @end deftypefn |
559 | 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 function h = image (varargin) |
7189 | 71 |
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
|
72 [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
|
73 |
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
|
74 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
|
75 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
76 do_new = true; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
77 if (nargin == 0) |
19324
68db8396c378
Make "image ()" use the default image cdata
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18899
diff
changeset
|
78 img = get (0, "defaultimagecdata"); |
7276 | 79 x = y = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18622
diff
changeset
|
80 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
|
81 ## Low-Level syntax |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
82 do_new = false; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
83 x = y = img = []; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
84 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
|
85 if (idx) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
86 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
|
87 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
|
88 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
89 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
|
90 if (idx) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
91 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
|
92 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
|
93 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
94 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
|
95 if (idx) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 elseif (nargin == 1 || chararg == 2) |
7276 | 100 img = varargin{1}; |
101 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
|
102 elseif (nargin == 2 || chararg == 3) |
7276 | 103 print_usage (); |
7189 | 104 else |
7276 | 105 x = varargin{1}; |
106 y = varargin{2}; | |
107 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
|
108 chararg = 4; |
15064
489736962e80
image.m: Don't accept complex image data (bug #36866)
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
109 endif |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
110 |
26184
572329faeb3b
image.m: Validate image data is not complex (bug #55170).
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
111 if (iscomplex (img)) |
572329faeb3b
image.m: Validate image data is not complex (bug #55170).
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
112 error ("image: IMG data can not be complex"); |
572329faeb3b
image.m: Validate image data is not complex (bug #55170).
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
113 endif |
572329faeb3b
image.m: Validate image data is not complex (bug #55170).
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
114 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
115 oldfig = []; |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
116 if (! isempty (hax)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
117 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
|
118 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
119 unwind_protect |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
120 if (do_new) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
121 hax = newplot (hax); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
122 elseif (isempty (hax)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
123 hax = gca (); |
18821
87c3848cf3c0
Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents:
18683
diff
changeset
|
124 else |
87c3848cf3c0
Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents:
18683
diff
changeset
|
125 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
|
126 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
127 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
128 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
|
129 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
130 unwind_protect_cleanup |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
131 if (! isempty (oldfig)) |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
132 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
|
133 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
134 end_unwind_protect |
7276 | 135 |
7189 | 136 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
|
137 h = htmp; |
7189 | 138 endif |
139 | |
140 endfunction | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
141 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
142 ## Generic image creation. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
143 ## |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
144 ## 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
|
145 ## @var{x} and @var{y}. |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
146 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
147 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
|
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)) |
18899
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
152 xdata = []; |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
153 else |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
154 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
|
155 endif |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
156 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
157 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
|
158 ydata = []; |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
159 else |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
160 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
|
161 endif |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
162 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
163 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
|
164 ## 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
|
165 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
|
166 dx = diff (x); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
167 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
|
168 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
|
169 dy = diff (y); |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 "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
|
175 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
|
176 endif |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
177 |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
178 endif # ! isempty (img) |
13980
bd2be36fd949
image.m: Warn if input coordinates are not linearly spaced.
Ben Abbott <bpabbott@mac.com>
parents:
13173
diff
changeset
|
179 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
180 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
|
181 ## 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
|
182 ## 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
|
183 ## 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
|
184 ## 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
|
185 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
|
186 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
|
187 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
|
188 endif |
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
189 endif # ! isempty (img) |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
190 |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
191 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
|
192 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
193 endif # do_new |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
194 |
19962
2e7497ff2535
image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
195 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
|
196 "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
|
197 |
2e7497ff2535
image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
198 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
|
199 && 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
|
200 ## 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
|
201 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
|
202 endif |
2e7497ff2535
image.m: Don't draw new image object twice for performance (bug #44567).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
203 |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
204 endfunction |
10942
48a1812fcc3a
image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents:
10818
diff
changeset
|
205 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
206 |
10942
48a1812fcc3a
image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents:
10818
diff
changeset
|
207 %!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
|
208 %! 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
|
209 %! 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
|
210 %! 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
|
211 %! 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
|
212 %! 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
|
213 %! 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
|
214 %! 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
|
215 %! 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
|
216 %! 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
|
217 %! 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
|
218 %! 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
|
219 %! 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
|
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 %! 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
|
223 %! 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
|
224 %! 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
|
225 %! title ("image (-x, -y, img)"); |
10942
48a1812fcc3a
image.m: Matlab compatible axis limits, add demo.
Ben Abbott <bpabbott@mac.com>
parents:
10818
diff
changeset
|
226 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22488
diff
changeset
|
227 ## 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
|
228 %!test <*42121> |
18899
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
229 %! 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
|
230 %! unwind_protect |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
231 %! 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
|
232 %! 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
|
233 %! 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
|
234 %! assert (get (hi, "xdata"), [1 nx]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
235 %! assert (get (hi, "ydata"), [1 ny]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
236 %! 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
|
237 %! assert (get (hi, "xdata"), [1 nx/2]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
238 %! 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
|
239 %! |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
240 %! 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
|
241 %! 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
|
242 %! set (hi, "cdata", cdata); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
243 %! assert (get (hi, "xdata"), [10 100]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
244 %! 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
|
245 %! |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
246 %! set (hi, "ydata", []); # ydatamode is now auto |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
247 %! 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
|
248 %! assert (get (hi, "xdata"), [10 100]); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
249 %! 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
|
250 %! unwind_protect_cleanup |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
251 %! close (hf); |
18899
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
252 %! end_unwind_protect |
3d9e503aea2c
Update image "x/ydata" when "cdata" is changed (bug #42121)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18821
diff
changeset
|
253 |
17692
38cf56b77274
Overhaul image, imagesc to use newplot and support low-level invocation form.
Rik <rik@octave.org>
parents:
17689
diff
changeset
|
254 ## FIXME: Need %!tests for linear |
26184
572329faeb3b
image.m: Validate image data is not complex (bug #55170).
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
255 |
572329faeb3b
image.m: Validate image data is not complex (bug #55170).
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
256 %!error <IMG data can not be complex> image ([1, i]) |