Mercurial > octave
annotate scripts/image/rgb2hsv.m @ 33625:d213a148b3f1 default tip
ensure exp. terminal widget has focus at startup
* main-window.cc (main_window): call focus_command_window only if
event loop is idle by using a single shot timer
* main-window.h: make focus_command_window a public slot
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 26 May 2024 02:29:44 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 1999-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3803 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3803 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
3803 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
3803 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3803 | 25 |
26 ## -*- texinfo -*- | |
22766
6033e2e4d5ea
doc: Clarify inputs and outputs for rgb2hsv.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
27 ## @deftypefn {} {@var{hsv_map} =} rgb2hsv (@var{rgb_map}) |
6033e2e4d5ea
doc: Clarify inputs and outputs for rgb2hsv.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
28 ## @deftypefnx {} {@var{hsv_img} =} rgb2hsv (@var{rgb_img}) |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
29 ## Transform a colormap or image from RGB to HSV color space. |
3803 | 30 ## |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
31 ## 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
|
32 ## |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
33 ## 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
|
34 ## (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
|
35 ## 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
|
36 ## 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
|
37 ## 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
|
38 ## |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
39 ## 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
|
40 ## |
24610
3ad53e4793fc
rgb2gray: New function to convert RGB images to grayscale images.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
41 ## @seealso{hsv2rgb, rgb2ind, rgb2gray} |
3803 | 42 ## @end deftypefn |
43 | |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
44 function hsv = rgb2hsv (rgb) |
3803 | 45 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
46 if (nargin < 1) |
6046 | 47 print_usage (); |
3803 | 48 endif |
49 | |
20676
1672bb8882dd
Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents:
20665
diff
changeset
|
50 [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
|
51 = colorspace_conversion_input_check ("rgb2hsv", "RGB", rgb); |
3803 | 52 |
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
|
53 ## 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
|
54 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
|
55 v = max (rgb, [], 2); |
3803 | 56 |
3904 | 57 ## 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
|
58 h = zeros (rows (rgb), 1); |
3904 | 59 notgray = (s != v); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 |
3904 | 61 ## blue hue |
62 idx = (v == rgb(:,3) & notgray); | |
63 if (any (idx)) | |
64 h(idx) = 2/3 + 1/6 * (rgb(idx,1) - rgb(idx,2)) ./ (v(idx) - s(idx)); | |
65 endif | |
3803 | 66 |
3904 | 67 ## green hue |
68 idx = (v == rgb(:,2) & notgray); | |
69 if (any (idx)) | |
70 h(idx) = 1/3 + 1/6 * (rgb(idx,3) - rgb(idx,1)) ./ (v(idx) - s(idx)); | |
71 endif | |
3803 | 72 |
3904 | 73 ## red hue |
74 idx = (v == rgb(:,1) & notgray); | |
75 if (any (idx)) | |
76 h(idx) = 1/6 * (rgb(idx,2) - rgb(idx,3)) ./ (v(idx) - s(idx)); | |
77 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
|
78 h(h < 0) += 1; # correct for negative red |
3803 | 79 |
3904 | 80 ## set the saturation |
81 s(! notgray) = 0; | |
82 s(notgray) = 1 - s(notgray) ./ v(notgray); | |
3803 | 83 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
84 hsv = [h, s, v]; |
20676
1672bb8882dd
Remove unused arguments in private functions for colorspace arguments.
Carnë Draug <carandraug@octave.org>
parents:
20665
diff
changeset
|
85 hsv = colorspace_conversion_revert (hsv, sz, is_im, is_nd); |
3803 | 86 |
87 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
|
88 |
21759
b002b4331a12
maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents:
21580
diff
changeset
|
89 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
90 ## 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
|
91 %!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
|
92 %!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
|
93 %!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
|
94 %!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
|
95 %!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
|
96 %!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
|
97 %!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
|
98 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
99 ## 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
|
100 %!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
|
101 |
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
|
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_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
|
104 %! 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
|
105 |
806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents:
14260
diff
changeset
|
106 %!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
|
107 %! 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
|
108 %! 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
|
109 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
110 ## support sparse input |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
111 %!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
|
112 %!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
|
113 %!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
|
114 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
115 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
116 %!error <Invalid call> rgb2hsv () |
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
|
117 %!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
|
118 %!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
|
119 |
20369
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
120 ## Test ND input |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
121 %!test |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
122 %! 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
|
123 %! hsv = zeros (size (rgb)); |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
124 %! for i = 1:5 |
131ce8cfaa80
Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
125 %! 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
|
126 %! endfor |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
127 %! 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
|
128 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
129 ## 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
|
130 ## 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
|
131 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
132 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
133 %! hsv = rgb2hsv (rand (10, 10, 3)); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
134 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
135 %! 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
|
136 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
137 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
138 %! 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
|
139 %! assert (class (hsv), "single"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
140 %! 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
|
141 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
142 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
143 %! 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
|
144 %! hsv = rgb2hsv (rgb); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
145 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
146 %! 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
|
147 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
148 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
149 %! 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
|
150 %! hsv = rgb2hsv (rgb); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
151 %! assert (class (hsv), "single"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
152 %! 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
|
153 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
154 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
155 %! 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
|
156 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
157 %! 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
|
158 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
159 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
160 %! 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
|
161 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
162 %! 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
|
163 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
164 %!test |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
165 %! 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
|
166 %! assert (class (hsv), "double"); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
167 %! 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
|
168 |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
169 %!test |
a278de349250
Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents:
20663
diff
changeset
|
170 %! 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
|
171 %! 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
|
172 %! [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
|
173 %! 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
|
174 %! 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
|
175 %! |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
176 %! assert (rgb2hsv (rgb_double), expected); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
177 %! assert (rgb2hsv (rgb_uint8), expected, 0.005); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
178 %! assert (rgb2hsv (single (rgb_double)), single (expected)); |