comparison scripts/image/rgb2hsv.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children 72c96de7a403
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
22 ## 22 ##
23 ## A color in the RGB space consists of the red, green and blue intensities. 23 ## A color in the RGB space consists of the red, green and blue intensities.
24 ## 24 ##
25 ## In the HSV space each color is represented by their hue, saturation 25 ## In the HSV space each color is represented by their hue, saturation
26 ## and value (brightness). Value gives the amount of light in the color. 26 ## and value (brightness). Value gives the amount of light in the color.
27 ## Hue describes the dominant wavelength. 27 ## Hue describes the dominant wavelength.
28 ## Saturation is the amount of hue mixed into the color. 28 ## Saturation is the amount of hue mixed into the color.
29 ## @seealso{hsv2rgb} 29 ## @seealso{hsv2rgb}
30 ## @end deftypefn 30 ## @end deftypefn
31 31
32 ## Author: Kai Habel <kai.habel@gmx.de> 32 ## Author: Kai Habel <kai.habel@gmx.de>
63 v = max (rgb')'; 63 v = max (rgb')';
64 64
65 ## set hue to zero for undefined values (gray has no hue) 65 ## set hue to zero for undefined values (gray has no hue)
66 h = zeros (size (v)); 66 h = zeros (size (v));
67 notgray = (s != v); 67 notgray = (s != v);
68 68
69 ## blue hue 69 ## blue hue
70 idx = (v == rgb(:,3) & notgray); 70 idx = (v == rgb(:,3) & notgray);
71 if (any (idx)) 71 if (any (idx))
72 h(idx) = 2/3 + 1/6 * (rgb(idx,1) - rgb(idx,2)) ./ (v(idx) - s(idx)); 72 h(idx) = 2/3 + 1/6 * (rgb(idx,1) - rgb(idx,2)) ./ (v(idx) - s(idx));
73 endif 73 endif
91 ## set the saturation 91 ## set the saturation
92 s(! notgray) = 0; 92 s(! notgray) = 0;
93 s(notgray) = 1 - s(notgray) ./ v(notgray); 93 s(notgray) = 1 - s(notgray) ./ v(notgray);
94 94
95 hsv_map = [h, s, v]; 95 hsv_map = [h, s, v];
96 96
97 ## If input was an image, convert it back into one. 97 ## If input was an image, convert it back into one.
98 if (is_image) 98 if (is_image)
99 hsv_map = reshape (hsv_map, Sz); 99 hsv_map = reshape (hsv_map, Sz);
100 endif 100 endif
101 101