annotate scripts/image/cubehelix.m @ 21973:894239974868

colormap: remove functionality to list and register colormaps (bug #48272) * colormap.m: remove the unused functionality which clashes with the possibility of having a colormap named list. It's also not that useful since there's no requirement to register a colormap, and therefore no guarantees that the list is complete. * autumn.m, bone.m, cool.m, copper.m, cubehelix.m, flag.m, gray.m, hot.m, hsv.m, jet.m, lines.m, ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, viridis.m, white.m, winter.m: remove registration to colormap().
author Carnë Draug <carandraug@octave.org>
date Mon, 20 Jun 2016 18:24:18 +0100
parents ffad2baa90f7
children 1c4cd12987f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19613
diff changeset
1 ## Copyright (C) 2014-2015 Carnë Draug
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
2 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
4 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
8 ## your option) any later version.
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
9 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
18
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20724
diff changeset
20 ## @deftypefn {} {@var{map} =} cubehelix ()
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20724
diff changeset
21 ## @deftypefnx {} {@var{map} =} cubehelix (@var{n})
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22 ## Create cubehelix colormap.
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
23 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
24 ## This colormap varies from black to white going though blue, green, and red
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25 ## tones while maintaining a monotonically increasing perception of intensity.
21315
ea2c2e08ceda doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents: 20852
diff changeset
26 ## This is achieved by traversing a color cube from black to white through
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27 ## a helix, hence the name cubehelix, while taking into account the perceived
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
28 ## brightness of each channel according to the NTSC specifications from 1953.
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30 ## @example
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31 ## rgbplot (cubehelix (256))
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 ## @end example
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20098
diff changeset
34 ## The argument @var{n} must be a scalar.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20098
diff changeset
35 ## If unspecified, the length of the current colormap, or 64, is used.
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20098
diff changeset
37 ## Reference: Green, D. A., 2011,
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20098
diff changeset
38 ## @cite{"A @nospell{colour} scheme for the display of astronomical intensity
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20098
diff changeset
39 ## images"}, Bulletin of the Astronomical Society of India, 39, 289.
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
40 ##
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
41 ## @seealso{colormap}
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 ## @end deftypefn
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
43
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 ## Author: Carnë Draug <carandraug@octave.org>
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 function map = cubehelix (n = rows (colormap ()), start = 0.5,
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 rots = -1.5, hue = 1, gamma = 1)
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
48
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
49 if (nargin > 5)
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 21315
diff changeset
50 print_usage ();
19611
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
51 elseif (! isscalar (n))
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
52 error ("cubehelix: N must be a scalar");
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21385
diff changeset
54
19613
e8e3a89fa370 Fix colormap functions when N is not of class double (bug #44070)
Carnë Draug <carandraug@octave.org>
parents: 19611
diff changeset
55 n = double (n);
19611
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
56 if (n > 1)
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
57 coeff = [ -0.14861 -0.29227 1.97294
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
58 1.78277 -0.90649 0.00000];
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59
19611
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
60 fract = ((0:n-1) / (n-1))';
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
61 angle = 2 * pi * (start/3 + 1 + rots*fract);
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 20158
diff changeset
62 fract .^= gamma;
19611
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
63 amp = hue * fract .* (1-fract) /2;
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
64 map = fract + amp .* ([cos(angle) sin(angle)] * coeff);
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65
19611
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
66 ## Clip values (only in case users have changed values of hue or gamma)
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
67 map(map < 0) = 0;
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
68 map(map > 1) = 1;
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
69 elseif (n > 0)
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
70 map = [0, 0, 0];
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
71 else
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
72 map = zeros (0, 3);
ed4eeb4314e6 cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents: 19530
diff changeset
73 endif
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
74
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
75 endfunction
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
76
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
77
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21385
diff changeset
78 ## A better demo of this colormap would be a 3D plot in NTSC instead of
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21385
diff changeset
79 ## RGB values. That would really show what this colormap is about.
19530
5ab6fcf32d1e New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
80 %!demo
20724
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20231
diff changeset
81 %! ## Show the 'cubehelix' colormap profile and as an image
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20231
diff changeset
82 %! cmap = cubehelix (256);
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20231
diff changeset
83 %! subplot (2, 1, 1);
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20231
diff changeset
84 %! rgbplot (cmap, "composite");
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20231
diff changeset
85 %! subplot (2, 1, 2);
0338dc274ec5 Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents: 20231
diff changeset
86 %! rgbplot (cmap);
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21385
diff changeset
87