Mercurial > octave
annotate scripts/image/bone.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 1999-2020 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
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
6788 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
6788 | 10 ## 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
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
6788 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
6788 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## 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
|
21 ## <https://www.gnu.org/licenses/>. |
6788 | 22 |
23 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20724
diff
changeset
|
24 ## @deftypefn {} {@var{map} =} bone () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20724
diff
changeset
|
25 ## @deftypefnx {} {@var{map} =} bone (@var{n}) |
11420
466ba499eff5
Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents:
9751
diff
changeset
|
26 ## Create color colormap. This colormap varies from black to white with |
466ba499eff5
Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents:
9751
diff
changeset
|
27 ## gray-blue shades. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## The argument @var{n} must be a scalar. |
11420
466ba499eff5
Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents:
9751
diff
changeset
|
30 ## If unspecified, the length of the current colormap, or 64, is used. |
6788 | 31 ## @seealso{colormap} |
32 ## @end deftypefn | |
33 | |
34 ## Author: Kai Habel <kai.habel@gmx.de> | |
35 | |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
36 function map = bone (n) |
6788 | 37 |
19613
e8e3a89fa370
Fix colormap functions when N is not of class double (bug #44070)
Carnë Draug <carandraug@octave.org>
parents:
19593
diff
changeset
|
38 if (nargin > 1) |
6788 | 39 print_usage (); |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
40 elseif (nargin == 1) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
41 if (! isscalar (n)) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
42 error ("bone: N must be a scalar"); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
43 endif |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
44 n = double (n); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
45 else |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
46 hf = get (0, "currentfigure"); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
47 if (! isempty (hf)) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
48 n = rows (get (hf, "colormap")); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
49 else |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
50 n = 64; |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
51 endif |
6788 | 52 endif |
53 | |
11420
466ba499eff5
Update docstrings for colormap files.
Rik <octave@nomad.inbox5.com>
parents:
9751
diff
changeset
|
54 if (n == 1) |
16464
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
55 map = [1/8 1/8 1/8]; |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
56 elseif (n == 2) |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
57 map = [1/16 1/8 1/8 |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
58 1 1 1 ]; |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
59 elseif (n > 2) |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
60 x = [0:n-1]' / (n-1); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
61 |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
62 idx = floor (3/4*n); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
63 nel = n - idx + 1; # number of elements |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
64 rem = mod (n, 8); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
65 switch (rem) |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
66 case {2, 4} |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
67 base = 1 / (16 + 2*(n-rem)); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
68 case {5, 7} |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
69 base = 1 / (24 + 2*(n-rem)); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
70 otherwise |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
71 base = 0; |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
72 endswitch |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
73 r(1:idx,1) = 7/8 * x(1:idx); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
74 r(idx:n,1) = linspace (7/8 * x(idx) + base, 1, nel); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
75 |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
76 idx = floor (3/8 * n); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
77 nel = idx + 1; |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
78 g(1:idx,1) = 7/8 * x(1:idx); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
79 g(idx:2*idx,1) = linspace (7/8 * x(idx), 7/8 * x(2*idx) + 1/8, nel); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
80 g(2*idx+1:n,1) = 7/8 * x(2*idx+1:n) + 1/8; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
81 |
16464
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
82 base = 1 / (8*idx); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
83 nel = idx; |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
84 b(1:idx,1) = linspace (base, 7/8 * x(idx) + 1/8, nel); |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
85 b(idx:n,1) = 7/8 * x(idx:n) + 1/8; |
328048fd43b8
bone.m: Make colormap compatible with Matlab (bug #36473).
Rik <rik@octave.org>
parents:
15720
diff
changeset
|
86 |
6788 | 87 map = [r, g, b]; |
88 else | |
14641
5f1d4def40e1
improve compatibility of colormap functions
Carnë Draug <carandraug+dev@gmail.com>
parents:
14640
diff
changeset
|
89 map = zeros (0, 3); |
6788 | 90 endif |
14279
f205d0074687
Update colormap files with faster code.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
91 |
6788 | 92 endfunction |
9751
2b0cc0b6db61
Add demos for colormap functions
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
93 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
94 |
9751
2b0cc0b6db61
Add demos for colormap functions
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
95 %!demo |
20724
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20158
diff
changeset
|
96 %! ## Show the 'bone' colormap profile and as an image |
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20158
diff
changeset
|
97 %! cmap = bone (256); |
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20158
diff
changeset
|
98 %! subplot (2, 1, 1); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21973
diff
changeset
|
99 %! rgbplot (cmap, "composite"); |
20724
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20158
diff
changeset
|
100 %! subplot (2, 1, 2); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21973
diff
changeset
|
101 %! rgbplot (cmap); |