annotate scripts/image/rgbplot.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 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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: 32002
diff changeset
3 ## Copyright (C) 2012-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27106
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/>.
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
7 ##
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
8 ## This file is part of Octave.
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
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: 23220
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: 22343
diff changeset
13 ## (at your option) any later version.
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
14 ##
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22343
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22343
diff changeset
18 ## GNU General Public License for more details.
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
19 ##
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
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: 23220
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 ########################################################################
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
25
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20723
diff changeset
27 ## @deftypefn {} {} rgbplot (@var{cmap})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20723
diff changeset
28 ## @deftypefnx {} {} rgbplot (@var{cmap}, @var{style})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20723
diff changeset
29 ## @deftypefnx {} {@var{h} =} rgbplot (@dots{})
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
30 ## Plot the components of a colormap.
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
31 ##
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
32 ## Two different @var{style}s are available for displaying the @var{cmap}:
15715
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
33 ##
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
34 ## @table @asis
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
35 ## @item profile (default)
15715
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
36 ## Plot the RGB line profile of the colormap for each of the channels (red,
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
37 ## green and blue) with the plot lines colored appropriately. Each line
22343
029c5f4eac3a rgbplot.m: Don't use Octave-only plot() syntax.
Rik <rik@octave.org>
parents: 22323
diff changeset
38 ## represents the intensity of an RGB component across the colormap.
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
39 ##
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
40 ## @item composite
15715
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
41 ## Draw the colormap across the X-axis so that the actual index colors are
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
42 ## visible rather than the individual color components.
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
43 ##
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
44 ## @end table
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
45 ##
15517
3f1b306e2ba9 rgbplot: return graphics handle if requested
Carnë Draug <carandraug+dev@gmail.com>
parents: 15515
diff changeset
46 ## The optional return value @var{h} is a graphics handle to the created plot.
3f1b306e2ba9 rgbplot: return graphics handle if requested
Carnë Draug <carandraug+dev@gmail.com>
parents: 15515
diff changeset
47 ##
15716
e8a4b99f8bd8 Correct typo in docstring in changeset 6ae93518356c.
Ben Abbott <bpabbott@mac.com>
parents: 15715
diff changeset
48 ## Run @code{demo rgbplot} to see an example of @code{rgbplot} and each style
15715
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
49 ## option.
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
50 ## @seealso{colormap}
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
51 ## @end deftypefn
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
52
16472
293f5479a7e7 rgbplot.m: Set the default style to "profile"
Rik <rik@octave.org>
parents: 15716
diff changeset
53 function h = rgbplot (cmap, style = "profile")
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
54
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27923
diff changeset
55 if (nargin < 1)
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
56 print_usage ();
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
57 endif
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
58
15515
4beb3a4bd440 rgbplot.m, cmpermute.m, cmunique.m, ind2rgb.m, imwrite.m: use core iscolormap function
Carnë Draug <carandraug+dev@gmail.com>
parents: 14271
diff changeset
59 if (! iscolormap (cmap))
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15713
diff changeset
60 error ("rgbplot: CMAP must be a valid colormap");
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
61 elseif (! ischar (style))
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
62 error ("rgbplot: STYLE must be a string");
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
63 endif
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
64
32002
939e5d952675 Use upper/lower in preference to toupper/tolower to match Matlab.
Rik <rik@octave.org>
parents: 31706
diff changeset
65 switch (lower (style))
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
66 case "profile"
22343
029c5f4eac3a rgbplot.m: Don't use Octave-only plot() syntax.
Rik <rik@octave.org>
parents: 22323
diff changeset
67 x = 1:rows (cmap);
029c5f4eac3a rgbplot.m: Don't use Octave-only plot() syntax.
Rik <rik@octave.org>
parents: 22323
diff changeset
68 htmp = plot (x,cmap(:,1),"r", x,cmap(:,2),"g", x,cmap(:,3),"b");
27106
6bfd3a890185 Consolidate separate calls to set() in to one call for interpreter efficiency.
Rik <rik@octave.org>
parents: 26376
diff changeset
69 set (gca, "ytick", 0:0.1:1, "xlim", [0 rows(cmap)]);
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
70 case "composite"
22343
029c5f4eac3a rgbplot.m: Don't use Octave-only plot() syntax.
Rik <rik@octave.org>
parents: 22323
diff changeset
71 htmp = image (1:rows (cmap));
029c5f4eac3a rgbplot.m: Don't use Octave-only plot() syntax.
Rik <rik@octave.org>
parents: 22323
diff changeset
72 set (gca, "ytick", []);
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
73 colormap (cmap);
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
74 otherwise
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
75 error ("rgbplot: unknown STYLE '%s'", style);
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
76 endswitch
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
77 xlabel ("color index");
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
78
15517
3f1b306e2ba9 rgbplot: return graphics handle if requested
Carnë Draug <carandraug+dev@gmail.com>
parents: 15515
diff changeset
79 if (nargout > 0)
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15713
diff changeset
80 h = htmp;
15517
3f1b306e2ba9 rgbplot: return graphics handle if requested
Carnë Draug <carandraug+dev@gmail.com>
parents: 15515
diff changeset
81 endif
3f1b306e2ba9 rgbplot: return graphics handle if requested
Carnë Draug <carandraug+dev@gmail.com>
parents: 15515
diff changeset
82
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
83 endfunction
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
84
15715
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
85
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
86 %!demo
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
87 %! clf;
15713
168e380c8f18 rgbplot.m: create style option and add new composite style
Carnë Draug <carandraug+dev@gmail.com>
parents: 15518
diff changeset
88 %! subplot (1, 2, 1);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 20852
diff changeset
89 %! rgbplot (ocean, "profile");
15715
6ae93518356c rgbplot.m. Match variable in docstring to function prototype.
Rik <rik@octave.org>
parents: 15714
diff changeset
90 %! subplot (1, 2, 2);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 20852
diff changeset
91 %! rgbplot (ocean, "composite");
14271
e2a14d1b4eaa rgbplot.m: Add new Matlab compatible function for plotting colormaps
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
92
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
93 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
94 %!error <Invalid call> rgbplot ()
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15713
diff changeset
95 %!error <CMAP must be a valid colormap> rgbplot ({0 1 0})
16472
293f5479a7e7 rgbplot.m: Set the default style to "profile"
Rik <rik@octave.org>
parents: 15716
diff changeset
96 %!error <STYLE must be a string> rgbplot ([0 1 0], 2)
22765
01aae08a0105 maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents: 22760
diff changeset
97 %!error <unknown STYLE 'nostyle'> rgbplot ([0 1 0], "nostyle")