Mercurial > hg > octave-nkf
annotate scripts/image/hsv2rgb.m @ 14552:86854d032a37
maint: miscellaneous style fixes for .m files
* audio/mu2lin.m, deprecated/cut.m, general/cplxpair.m,
general/genvarname.m, geometry/rectint.m, help/gen_doc_cache.m,
image/hsv2rgb.m, image/rainbow.m, io/textscan.m,
miscellaneous/bzip2.m, miscellaneous/compare_versions.m,
miscellaneous/fact.m, miscellaneous/menu.m, optimization/fminbnd.m,
optimization/fminunc.m, optimization/fzero.m, optimization/sqp.m,
plot/__gnuplot_drawnow__.m, plot/axis.m, plot/findobj.m,
plot/legend.m, plot/peaks.m, plot/private/__errplot__.m,
plot/private/__fltk_print__.m, plot/private/__go_draw_axes__.m,
plot/private/__patch__.m, polynomial/pchip.m, polynomial/residue.m,
signal/periodogram.m, sparse/sprandsym.m, statistics/base/moment.m,
statistics/distributions/expcdf.m, statistics/distributions/expinv.m,
statistics/distributions/exppdf.m, statistics/tests/prop_test_2.m,
statistics/tests/sign_test.m, statistics/tests/t_test.m,
statistics/tests/t_test_2.m, statistics/tests/t_test_regression.m,
strings/regexptranslate.m, time/datetick.m:
Style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Apr 2012 22:07:00 -0400 |
parents | 1f911333ed3d |
children | 806ea52af230 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 1999-2012 Kai Habel |
3803 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3803 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3803 | 18 |
19 ## -*- texinfo -*- | |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
20 ## @deftypefn {Function File} {@var{rgb_map} =} hsv2rgb (@var{hsv_map}) |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{rgb_img} =} hsv2rgb (@var{hsv_img}) |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
22 ## Transform a colormap or image from hue-saturation-value (HSV) space to |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
23 ## red-green-blue (RGB) space. |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
24 ## @seealso{rgb2hsv, ind2rgb, ntsc2rgb} |
3803 | 25 ## @end deftypefn |
26 | |
27 ## Author: Kai Habel <kai.habel@gmx.de> | |
28 ## Adapted-by: jwe | |
29 | |
30 function rgb_map = hsv2rgb (hsv_map) | |
31 | |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
32 ## Each color value x = (r,g,b) is calculated with |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
33 ## x = (1-sat)*val+sat*val*f_x(hue) |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
34 ## where f_x(hue) is a piecewise defined function for |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
35 ## each color with f_r(hue-2/3) = f_g(hue) = f_b(hue-1/3). |
3803 | 36 |
37 if (nargin != 1) | |
6046 | 38 print_usage (); |
3803 | 39 endif |
40 | |
7375 | 41 ## If we have an image convert it into a color map. |
42 if (ismatrix (hsv_map) && ndims (hsv_map) == 3) | |
43 is_image = true; | |
44 Sz = size (hsv_map); | |
45 hsv_map = [hsv_map(:,:,1)(:), hsv_map(:,:,2)(:), hsv_map(:,:,3)(:)]; | |
46 ## Convert to a double image. | |
47 if (isinteger (hsv_map)) | |
48 C = class (hsv_map); | |
49 low = double (intmin (C)); | |
50 high = double (intmax (C)); | |
51 hsv_map = (double (hsv_map) - low) / (high - low); | |
52 endif | |
53 else | |
54 is_image = false; | |
55 endif | |
56 | |
4030 | 57 if (! ismatrix (hsv_map) || columns (hsv_map) != 3) |
3803 | 58 error ("hsv2rgb: argument must be a matrix of size nx3"); |
59 endif | |
60 | |
61 ## set values <0 to 0 and >1 to 1 | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14260
diff
changeset
|
62 hsv_map = (hsv_map >= 0 & hsv_map <= 1) .* hsv_map ... |
3803 | 63 + (hsv_map < 0) .* 0 + (hsv_map > 1); |
64 | |
65 ## fill rgb map with v*(1-s) | |
66 rgb_map = kron ([1, 1, 1], hsv_map(:,3) .* (1 - hsv_map(:,2))); | |
67 | |
68 ## red(hue-2/3)=green(hue)=blue(hue-1/3) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
69 ## apply modulo 1 for red and blue |
3803 | 70 t = hsv_map(:,1); |
71 tp = t'; | |
72 hue = [(tp - 2/3 - floor (t - 2/3)'); | |
73 tp; | |
74 (tp - 1/3 - floor (t - 1/3)')]'; | |
75 | |
76 ## factor s*v -> f | |
77 f = kron ([1, 1, 1], hsv_map(:,2)) .* kron ([1, 1, 1], hsv_map(:,3)); | |
78 | |
79 ## add s*v* hue-function to rgb map | |
80 rgb_map = rgb_map + f .* (6 * (hue < 1/6) .* hue | |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
8920
diff
changeset
|
81 + (hue >= 1/6 & hue < 1/2) |
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
8920
diff
changeset
|
82 + (hue >= 1/2 & hue < 2/3) .* (4 - 6 * hue)); |
3803 | 83 |
7375 | 84 ## If input was an image, convert it back into one. |
85 if (is_image) | |
86 rgb_map = reshape (rgb_map, Sz); | |
87 endif | |
88 | |
3803 | 89 endfunction |