Mercurial > octave
annotate scripts/image/rgb2hsv.m @ 22323:bac0d6f07a3e
maint: Update copyright notices for 2016.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 01:05:19 -0400 |
parents | b002b4331a12 |
children | 3a2b891d0b33 6033e2e4d5ea |
rev | line source |
---|---|
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21759
diff
changeset
|
1 ## Copyright (C) 1999-2016 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 -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20676
diff
changeset
|
20 ## @deftypefn {} {@var{hsv_map} =} rgb2hsv (@var{rgb}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20676
diff
changeset
|
21 ## @deftypefnx {} {@var{hsv_map} =} rgb2hsv (@var{rgb}) |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
22 ## Transform a colormap or image from RGB to HSV color space. |
3803 | 23 ## |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
24 ## A color in the RGB space consists of red, green, and blue intensities. |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
25 ## |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
26 ## A color in HSV space is represented by hue, saturation and value |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
27 ## (brightness) levels in a cylindrical coordinate system. Hue is the |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
28 ## azimuth and describes the dominant color. Saturation is the radial |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
29 ## distance and gives the amount of hue mixed into the color. Value is |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
30 ## the height and is the amount of light in the color. |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
31 ## |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
32 ## Output class and size will be the same as input. |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
33 ## |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
34 ## @seealso{hsv2rgb, rgb2ind, rgb2ntsc} |
3803 | 35 ## @end deftypefn |
36 | |
37 ## Author: Kai Habel <kai.habel@gmx.de> | |
38 ## Adapted-by: jwe | |
39 | |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
40 function hsv = rgb2hsv (rgb) |
3803 | 41 |
42 if (nargin != 1) | |
6046 | 43 print_usage (); |
3803 | 44 endif |
45 | |
20676
1672bb8882dd
Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents:
20665
diff
changeset
|
46 [rgb, sz, is_im, is_nd] ... |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
47 = colorspace_conversion_input_check ("rgb2hsv", "RGB", rgb); |
3803 | 48 |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
49 ## get the max and min for each row |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
50 s = min (rgb, [], 2); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
51 v = max (rgb, [], 2); |
3803 | 52 |
3904 | 53 ## set hue to zero for undefined values (gray has no hue) |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
54 h = zeros (rows (rgb), 1); |
3904 | 55 notgray = (s != v); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
56 |
3904 | 57 ## blue hue |
58 idx = (v == rgb(:,3) & notgray); | |
59 if (any (idx)) | |
60 h(idx) = 2/3 + 1/6 * (rgb(idx,1) - rgb(idx,2)) ./ (v(idx) - s(idx)); | |
61 endif | |
3803 | 62 |
3904 | 63 ## green hue |
64 idx = (v == rgb(:,2) & notgray); | |
65 if (any (idx)) | |
66 h(idx) = 1/3 + 1/6 * (rgb(idx,3) - rgb(idx,1)) ./ (v(idx) - s(idx)); | |
67 endif | |
3803 | 68 |
3904 | 69 ## red hue |
70 idx = (v == rgb(:,1) & notgray); | |
71 if (any (idx)) | |
72 h(idx) = 1/6 * (rgb(idx,2) - rgb(idx,3)) ./ (v(idx) - s(idx)); | |
73 endif | |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
74 h(h < 0) += 1; # correct for negative red |
3803 | 75 |
3904 | 76 ## set the saturation |
77 s(! notgray) = 0; | |
78 s(notgray) = 1 - s(notgray) ./ v(notgray); | |
3803 | 79 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
80 hsv = [h, s, v]; |
20676
1672bb8882dd
Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents:
20665
diff
changeset
|
81 hsv = colorspace_conversion_revert (hsv, sz, is_im, is_nd); |
3803 | 82 |
83 endfunction | |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
84 |
21759
b002b4331a12
maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents:
21580
diff
changeset
|
85 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
86 ## Test pure colors and gray |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
87 %!assert (rgb2hsv ([1 0 0]), [0 1 1]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
88 %!assert (rgb2hsv ([0 1 0]), [1/3 1 1]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
89 %!assert (rgb2hsv ([0 0 1]), [2/3 1 1]) |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
90 %!assert (rgb2hsv ([1 1 0]), [1/6 1 1]) |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
91 %!assert (rgb2hsv ([0 1 1]), [1/2 1 1]) |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
92 %!assert (rgb2hsv ([1 0 1]), [5/6 1 1]) |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
93 %!assert (rgb2hsv ([0.5 0.5 0.5]), [0 0 0.5]) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
94 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
95 ## Test tolarant input checking on floats |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
96 %!assert (rgb2hsv ([1.5 1 1]), [0 1/3 1.5], eps) |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
97 |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
98 %!test |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
99 %! rgb_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:
14260
diff
changeset
|
100 %! assert (hsv2rgb (rgb2hsv (rgb_map)), rgb_map, 1e-6); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
101 |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
102 %!test |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
103 %! rgb_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:
14260
diff
changeset
|
104 %! assert (hsv2rgb (rgb2hsv (rgb_img)), rgb_img, 1e-6); |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
105 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
106 ## support sparse input |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
107 %!assert (rgb2hsv (sparse ([0 0 1])), sparse ([2/3 1 1])) |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
108 %!assert (rgb2hsv (sparse ([0 1 1])), sparse ([1/2 1 1])) |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
109 %!assert (rgb2hsv (sparse ([1 1 1])), sparse ([0 0 1])) |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
110 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
111 ## 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:
14260
diff
changeset
|
112 %!error rgb2hsv () |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
113 %!error rgb2hsv (1,2) |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
114 %!error <invalid data type 'cell'> rgb2hsv ({1}) |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
115 %!error <RGB must be a colormap or RGB image> rgb2hsv (ones (2,2)) |
15683
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
116 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
117 ## Test ND input |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
118 %!test |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
119 %! rgb = rand (16, 16, 3, 5); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
120 %! hsv = zeros (size (rgb)); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
121 %! for i = 1:5 |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
122 %! hsv(:,:,:,i) = rgb2hsv (rgb(:,:,:,i)); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
123 %! endfor |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
124 %! assert (rgb2hsv (rgb), hsv); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
125 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
126 ## 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
|
127 ## 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
|
128 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
129 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
130 %! hsv = rgb2hsv (rand (10, 10, 3)); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
131 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
132 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
133 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
134 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
135 %! hsv = rgb2hsv (rand (10, 10, 3, "single")); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
136 %! assert (class (hsv), "single"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
137 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
138 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
139 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
140 %! 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
|
141 %! hsv = rgb2hsv (rgb); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
142 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
143 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
144 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
145 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
146 %! 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
|
147 %! hsv = rgb2hsv (rgb); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
148 %! assert (class (hsv), "single"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
149 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
150 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
151 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
152 %! hsv = rgb2hsv (randi ([0 255], 10, 10, 3, "uint8")); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
153 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
154 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
155 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
156 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
157 %! hsv = rgb2hsv (randi ([0 65535], 10, 10, 3, "uint16")); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
158 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
159 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
160 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
161 %!test |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
162 %! hsv = rgb2hsv (randi ([-128 127], 10, 10, 3, "int8")); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
163 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
164 %! assert (size (hsv), [10 10 3]); |
20664
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
165 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
166 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
167 %! rgb_double = reshape ([1 0 1 .5 1 1 0 .5 0 1 1 .5], [2 2 3]); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
168 %! rgb_uint8 = reshape (uint8 ([255 0 255 128 255 255 0 128 0 255 255 128]), |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
169 %! [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
|
170 %! rgb_int16 = int16 (double (rgb_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
|
171 %! expected = reshape ([1/6 1/2 5/6 0 1 1 1 0 1 1 1 .5], [2 2 3]); |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
172 %! |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
173 %! assert (rgb2hsv (rgb_double), expected); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
174 %! assert (rgb2hsv (rgb_uint8), expected, 0.005); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
175 %! assert (rgb2hsv (single (rgb_double)), single (expected)); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
176 |