Mercurial > octave
annotate scripts/image/hsv2rgb.m @ 21562:6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
* make_int.cc, file-editor-tab.h, file-editor.cc, shortcut-manager.h,
__contourc__.cc, cellfun.cc, debug.cc, errwarn.h, graphics.in.h, jit-ir.h,
oct-stream.cc, quadcc.cc, qz.cc, sparse-xdiv.cc, symtab.cc, __init_fltk__.cc,
ov-class.cc, ov-float.h, ov-scalar.h, op-int.h, CNDArray.cc, CSparse.cc,
MSparse.cc, Sparse.cc, boolNDArray.cc, chNDArray.cc, dNDArray.cc, dSparse.cc,
fCNDArray.cc, fNDArray.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc,
int8NDArray.cc, intNDArray.cc, uint16NDArray.cc, uint32NDArray.cc,
uint64NDArray.cc, uint8NDArray.cc, randgamma.h, randmtzig.h, randpoisson.c,
randpoisson.h, Sparse-op-defs.h, oct-time.cc, kpse.cc, lo-array-errwarn.h,
lo-ieee.h, del2.m, num2str.m, __isequal__.m, lookfor.m, hsv2rgb.m,
colorspace_conversion_revert.m, fminbnd.m, create_pkgadddel.m, shading.m,
struct2hdl.m, gallery.m, discrete_cdf.m, kolmogorov_smirnov_test.m, assert.m,
datestr.m, classes.tst, jit.tst:
Eliminate accidental double spaces in code.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 30 Mar 2016 15:19:12 -0700 |
parents | acd6e203031d |
children | ecce63c99c3f |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1999-2015 Kai Habel |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
2 ## Copyright (C) 2015 Carnë Draug |
3803 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3803 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3803 | 19 |
20 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20716
diff
changeset
|
21 ## @deftypefn {} {@var{rgb_map} =} hsv2rgb (@var{hsv_map}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20716
diff
changeset
|
22 ## @deftypefnx {} {@var{rgb_img} =} hsv2rgb (@var{hsv_img}) |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
23 ## Transform a colormap or image from HSV to RGB color space. |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
24 ## |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
25 ## A color in HSV space is represented by hue, saturation and value |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
26 ## (brightness) levels in a cylindrical coordinate system. Hue is the |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
27 ## azimuth and describes the dominant color. Saturation is the radial |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
28 ## distance and gives the amount of hue mixed into the color. Value is |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
29 ## the height and is the amount of light in the color. |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
30 ## |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
31 ## The input can be both a colormap or RGB image. In the case of floating |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
32 ## point input, values are expected to be on the [0 1] range. In the case |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
33 ## of hue (azimuth), since the value corresponds to an angle, |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
34 ## @code{mod (h, 1)} is used. |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
35 ## |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
36 ## @example |
20716
1ecee53513d7
doc: Peridodic grammar check of documentation.
Rik <rik@octave.org>
parents:
20676
diff
changeset
|
37 ## @group |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
38 ## >> hsv2rgb ([0.5 1 1]) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
39 ## @result{} ans = 0 1 1 |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
40 ## |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
41 ## >> hsv2rgb ([2.5 1 1]) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
42 ## @result{} ans = 0 1 1 |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
43 ## |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
44 ## >> hsv2rgb ([3.5 1 1]) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
45 ## @result{} ans = 0 1 1 |
20716
1ecee53513d7
doc: Peridodic grammar check of documentation.
Rik <rik@octave.org>
parents:
20676
diff
changeset
|
46 ## @end group |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
47 ## @end example |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
48 ## |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
49 ## Output class and size will be the same as input. |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
50 ## |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
51 ## @seealso{rgb2hsv, ind2rgb, ntsc2rgb} |
3803 | 52 ## @end deftypefn |
53 | |
54 ## Author: Kai Habel <kai.habel@gmx.de> | |
55 ## Adapted-by: jwe | |
56 | |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
57 function rgb = hsv2rgb (hsv) |
3803 | 58 |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 ## 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
|
60 ## 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
|
61 ## 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
|
62 ## each color with f_r(hue-2/3) = f_g(hue) = f_b(hue-1/3). |
3803 | 63 |
64 if (nargin != 1) | |
6046 | 65 print_usage (); |
3803 | 66 endif |
67 | |
20676
1672bb8882dd
Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents:
20665
diff
changeset
|
68 [hsv, sz, is_im, is_nd] ... |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
69 = colorspace_conversion_input_check ("hsv2rgb", "HSV", hsv); |
3803 | 70 |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
71 h = hsv(:,1); |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
72 s = hsv(:,2); |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
73 v = hsv(:,3); |
3803 | 74 |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
75 ## Values of Saturation and Value should also be in the [0 1] range. With |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
76 ## the exception of hue, values outside this range don't make any sense |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
77 ## in a cylindrical coordinate system but we must return something for |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
78 ## Matlab compatibility. User case is when a function returns an hsv |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
79 ## image just slightly outside the range due to floating point rounding |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
80 ## errors. |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
81 |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
82 ## Prefill rgb map with v*(1-s) |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
83 rgb = repmat (v .* (1 - s), 1, 3); |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
84 |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
85 ## red = hue-2/3 : green = hue : blue = hue-1/3 |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
86 ## Apply modulo 1 to keep within range [0, 1] |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
87 hue = mod ([h-2/3 h h-1/3], 1); |
3803 | 88 |
89 ## factor s*v -> f | |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
90 f = repmat (s .* v, 1, 3); |
3803 | 91 |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
92 ## add s*v*hue-function to rgb map |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
93 rgb += f .* (6 * (hue < 1/6) .* hue |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
94 + (hue >= 1/6 & hue < 1/2) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
95 + (hue >= 1/2 & hue < 2/3) .* (4 - 6 * hue)); |
3803 | 96 |
20676
1672bb8882dd
Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents:
20665
diff
changeset
|
97 rgb = colorspace_conversion_revert (rgb, sz, is_im, is_nd); |
7375 | 98 |
3803 | 99 endfunction |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
100 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
101 ## Test pure colors |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
102 %!assert (hsv2rgb ([0 0 1]), [1 1 1]) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
103 %!assert (hsv2rgb ([1 1 0]), [0 0 0]) |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
104 %!assert (hsv2rgb ([0 1 1]), [1 0 0]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
105 %!assert (hsv2rgb ([1 1 1]), [1 0 0]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
106 %!assert (hsv2rgb ([1/3 1 1]), [0 1 0]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
107 %!assert (hsv2rgb ([2/3 1 1]), [0 0 1]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
108 |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
109 %!assert (hsv2rgb ([0 0.5 0.5]), hsv2rgb ([1 0.5 0.5])) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
110 |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
111 ## Not Matlab compatible (Matlab would return [1/2 1/12 1/12]) but |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
112 ## it's also invalid input. This is, however, the same output as Python |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
113 ## colorsys module. |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
114 %!assert (hsv2rgb ([0.5 -0.5 0.5]), [0.75 0.5 0.5]) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
115 |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
116 ## Not Matlab compatible. Matlab returns NaN when hue is outside the |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
117 ## [0 1] range. But since it's an angle, we can manage it. |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
118 %!assert (hsv2rgb ([0 0.5 0.5]), hsv2rgb ([2 0.5 0.5])) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
119 %!assert (hsv2rgb ([0.5 0.5 0.5]), hsv2rgb ([2.5 0.5 0.5]), eps) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
120 |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
121 %!test |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
122 %! hsv_map = rand (64, 3); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
123 %! assert (rgb2hsv (hsv2rgb (hsv_map)), hsv_map, 1e-6); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
124 |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
125 %!test |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
126 %! hsv_img = rand (64, 64, 3); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
127 %! assert (rgb2hsv (hsv2rgb (hsv_img)), hsv_img, 1e-6); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
128 |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
129 ## support sparse input |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
130 %!assert (hsv2rgb (sparse ([0 0 1])), sparse ([1 1 1])) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
131 %!assert (hsv2rgb (sparse ([0 1 1])), sparse ([1 0 0])) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
132 %!assert (hsv2rgb (sparse ([1 1 1])), sparse ([1 0 0])) |
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
133 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
134 ## Test input validation |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
135 %!error hsv2rgb () |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
136 %!error hsv2rgb (1,2) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14552
diff
changeset
|
137 %!error <invalid data type> hsv2rgb ({1}) |
20358
84ca63c8a038
hsv2rgb: relax input check and support for N dimensional images (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
138 %!error <HSV must be a colormap or HSV image> hsv2rgb (ones (2,2)) |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
139 |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
140 ## Test ND input |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
141 %!test |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
142 %! hsv = rand (16, 16, 3, 5); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
143 %! rgb = zeros (size (hsv)); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
144 %! for i = 1:5 |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
145 %! rgb(:,:,:,i) = hsv2rgb (hsv(:,:,:,i)); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
146 %! endfor |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
20358
diff
changeset
|
147 %! assert (hsv2rgb (hsv), rgb) |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
148 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
149 ## Test output class and size for input images. |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
150 ## Most of the tests only test for colormap input. |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
151 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
152 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
153 %! rgb = hsv2rgb (rand (10, 10, 3)); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
154 %! assert (class (rgb), "double") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
155 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
156 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
157 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
158 %! rgb = hsv2rgb (rand (10, 10, 3, "single")); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
159 %! assert (class (rgb), "single") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
160 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
161 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
162 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
163 %! rgb = (rand (10, 10, 3) * 3 ) - 0.5; # values outside range [0 1] |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
164 %! rgb = hsv2rgb (rgb); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
165 %! assert (class (rgb), "double") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
166 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
167 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
168 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
169 %! rgb = (rand (10, 10, 3, "single") * 3 ) - 0.5; # values outside range [0 1] |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
170 %! rgb = hsv2rgb (rgb); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
171 %! assert (class (rgb), "single") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
172 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
173 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
174 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
175 %! rgb = hsv2rgb (randi ([0 255], 10, 10, 3, "uint8")); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
176 %! assert (class (rgb), "double") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
177 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
178 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
179 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
180 %! rgb = hsv2rgb (randi ([0 65535], 10, 10, 3, "uint16")); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
181 %! assert (class (rgb), "double") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
182 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
183 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
184 %!test |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
185 %! rgb = hsv2rgb (randi ([-128 127], 10, 10, 3, "int8")); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
186 %! assert (class (rgb), "double") |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
187 %! assert (size (rgb), [10 10 3]) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
188 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
189 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
190 %! hsv_double = reshape ([2/3 1/3 1 0 1 1 1 0, 1 1 1 1], [2 2 3]); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
191 %! hsv_uint8 = reshape (uint8 ([170 85 255 0 255 255 255 0 255 255 255 255]), |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
192 %! [2 2 3]); |
20665
67e6343cd29a
Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20664
diff
changeset
|
193 %! hsv_int16 = int16 (double (hsv_double * uint16 (65535)) -32768); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
194 %! expected = reshape ([0 0 1 1 0 1 0 1 1 0 0 1], [2 2 3]); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
195 %! |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
196 %! assert (hsv2rgb (hsv_double), expected) |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
197 %! assert (hsv2rgb (hsv_uint8), expected) |
20665
67e6343cd29a
Add support for colorspace conversion of signed integers images (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20664
diff
changeset
|
198 %! assert (hsv2rgb (hsv_int16), expected) |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
199 %! assert (hsv2rgb (single (hsv_double)), single (expected), eps (single (2))) |