annotate scripts/image/rgb2hsv.m @ 20664:a278de349250

Add more tests for color space conversion functions (patch #8709) * scripts/image/hsv2rgb.m, scripts/image/ntsc2rgb.m, scripts/image/rgb2hsv.m, scripts/image/rgb2ntsc.m: most existing tests only checked conversion of colormaps (because those are easier to write). Add test for actual small images (MxNx3 arrays) converted. Also add tests for the output class.
author Carnë Draug <carandraug@octave.org>
date Wed, 28 Oct 2015 19:51:02 +0000
parents a5ed88c9eb14
children 67e6343cd29a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
2 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
4 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
9 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
14 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
18
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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{hsv_map} =} rgb2hsv (@var{rgb})
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefnx {Function File} {@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
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
35 ## @end deftypefn
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
36
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
37 ## Author: Kai Habel <kai.habel@gmx.de>
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
38 ## Adapted-by: jwe
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
41
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
42 if (nargin != 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
43 print_usage ();
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
44 endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
45
20663
a5ed88c9eb14 Only return floating point class on color conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20369
diff changeset
46 [rgb, cls, 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
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
52
3904
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
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
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
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
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
57 ## blue hue
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
58 idx = (v == rgb(:,3) & notgray);
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
59 if (any (idx))
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
60 h(idx) = 2/3 + 1/6 * (rgb(idx,1) - rgb(idx,2)) ./ (v(idx) - s(idx));
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
61 endif
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
62
3904
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
63 ## green hue
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
64 idx = (v == rgb(:,2) & notgray);
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
65 if (any (idx))
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
66 h(idx) = 1/3 + 1/6 * (rgb(idx,3) - rgb(idx,1)) ./ (v(idx) - s(idx));
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
67 endif
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
68
3904
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
69 ## red hue
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
70 idx = (v == rgb(:,1) & notgray);
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
71 if (any (idx))
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
72 h(idx) = 1/6 * (rgb(idx,2) - rgb(idx,3)) ./ (v(idx) - s(idx));
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
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
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
75
3904
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
76 ## set the saturation
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
77 s(! notgray) = 0;
6b00ac653c0f [project @ 2002-04-24 04:56:10 by jwe]
jwe
parents: 3803
diff changeset
78 s(notgray) = 1 - s(notgray) ./ v(notgray);
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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];
20663
a5ed88c9eb14 Only return floating point class on color conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20369
diff changeset
81 hsv = colorspace_conversion_revert (hsv, cls, sz, is_im, is_nd);
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
82
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
85 ## 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
86 %!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
87 %!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
88 %!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
89 %!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
90 %!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
91 %!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
92 %!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
93
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
94 ## 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
95 %!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
96
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 %!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
98 %! 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
99 %! 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
100
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 %!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
102 %! 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
103 %! 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
104
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
105 ## support sparse input
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
106 %!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
107 %!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
108 %!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
109
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
110 ## 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
111 %!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
112 %!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
113 %!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
114 %!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
115
20369
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
116 ## Test ND input
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
117 %!test
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
118 %! 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
119 %! hsv = zeros (size (rgb));
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
120 %! for i = 1:5
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
121 %! 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
122 %! endfor
131ce8cfaa80 Relax input in functions that convert between colorspaces (bug #45456)
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
123 %! 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
124
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
125 ## 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
126 ## 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
127
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
128 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
129 %! hsv = rgb2hsv (rand (10, 10, 3));
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
130 %! assert (class (hsv), "double")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
131 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
132
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
133 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
134 %! hsv = rgb2hsv (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
135 %! assert (class (hsv), "single")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
136 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
137
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
138 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
139 %! 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
140 %! hsv = rgb2hsv (rgb);
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
141 %! assert (class (hsv), "double")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
142 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
143
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
144 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
145 %! 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
146 %! hsv = rgb2hsv (rgb);
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
147 %! assert (class (hsv), "single")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
148 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
149
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
150 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
151 %! hsv = rgb2hsv (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
152 %! assert (class (hsv), "double")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
153 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
154
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
155 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
156 %! hsv = rgb2hsv (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
157 %! assert (class (hsv), "double")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
158 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
159
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
160 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
161 %! hsv = rgb2hsv (randi ([-128 127], 10, 10, 3, "uint16"));
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
162 %! assert (class (hsv), "double")
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
163 %! assert (size (hsv), [10 10 3])
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
164
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
165 %!test
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
166 %! 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
167 %! 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
168 %! [2 2 3]);
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
169 %! 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
170 %!
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
171 %! assert (rgb2hsv (rgb_double), expected)
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
172 %! assert (rgb2hsv (rgb_uint8), expected, 0.005)
a278de349250 Add more tests for color space conversion functions (patch #8709)
Carnë Draug <carandraug@octave.org>
parents: 20663
diff changeset
173 %! assert (rgb2hsv (single (rgb_double)), single (expected))