Mercurial > hg > octave-nkf
annotate scripts/image/cubehelix.m @ 20305:c164cfc24bdd
QtHandles: add annotations dialog
* libgui/graphics/annotation-dialog.h: new file
* libgui/graphics/annotation-dialog.cc: new file
* libgui/graphics/annotation-dialog.ui: new file
* libgui/graphics/Canvas.cc
(canvasMousePressEvent): call annotation_dialog when in TextMode.
* libgui/graphics/module.mk: add annotation-dialog to build
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sun, 19 Apr 2015 09:54:54 -0400 |
parents | 059a05bc398c |
children | 21dbaf135667 |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19810
diff
changeset
|
1 ## Copyright (C) 2014-2015 Carnë Draug |
19727
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 -*- |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {@var{map} =} cubehelix () |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{map} =} cubehelix (@var{n}) |
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. |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
26 ## This is achieved by transversing a color cube from black to white through |
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 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
34 ## The argument @var{n} must be a scalar and corresponds to the lenght of the |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
35 ## colormap. Defaults to the length of the current colormap. |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
36 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
37 ## Development of this colormap is described in @cite{Green, D. A., 2011, |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
38 ## "A colour scheme for the display of astronomical intensity images", |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
39 ## Bulletin of the Astronomical Society of India, 39, 289.}. |
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 ## PKG_ADD: colormap ("register", "cubehelix"); |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
47 ## PKG_DEL: colormap ("unregister", "cubehelix"); |
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 function map = cubehelix (n = rows (colormap ()), start = 0.5, |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
50 rots = -1.5, hue = 1, gamma = 1) |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
51 |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
52 if (nargin > 5) |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
53 print_usage () |
19808
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
54 elseif (! isscalar (n)) |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
55 error ("cubehelix: N must be a scalar"); |
19727
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
56 endif |
19810
e8e3a89fa370
Fix colormap functions when N is not of class double (bug #44070)
Carnë Draug <carandraug@octave.org>
parents:
19808
diff
changeset
|
57 n = double (n); |
19727
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
58 |
19808
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
59 if (n > 1) |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
60 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:
19727
diff
changeset
|
61 1.78277 -0.90649 0.00000]; |
19727
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
62 |
19808
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
63 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:
19727
diff
changeset
|
64 angle = 2 * pi * (start/3 + 1 + rots*fract); |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
65 fract = fract .^ gamma; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
66 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:
19727
diff
changeset
|
67 map = fract + amp .* ([cos(angle) sin(angle)] * coeff); |
19727
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
68 |
19808
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
69 ## 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:
19727
diff
changeset
|
70 map(map < 0) = 0; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
71 map(map > 1) = 1; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
72 |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
73 elseif (n > 0) |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
74 map = [0, 0, 0]; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
75 else |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
76 map = zeros (0, 3); |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19727
diff
changeset
|
77 endif |
19727
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
78 |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
79 endfunction |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
80 |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
81 |
19727
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
82 %!demo |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
83 %! subplot (1, 2, 1) |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
84 %! rgbplot (cubehelix (256), "composite") |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
85 %! subplot (1, 2, 2) |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
86 %! rgbplot (cubehelix (256)) |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
87 |