comparison scripts/image/hsv.m @ 16353:ca395af72d88

hsv.m: Make colormap compatible with Matlab (bug #36473). * scripts/image/hsv.m: Make colormap compatible with Matlab (bug #36473).
author Rik <rik@octave.org>
date Thu, 21 Mar 2013 07:45:04 -0700
parents 1a800034d443
children d63878346099
comparison
equal deleted inserted replaced
16352:b8a4f313e78e 16353:ca395af72d88
21 ## Create color colormap. This colormap begins with red, changes through 21 ## Create color colormap. This colormap begins with red, changes through
22 ## yellow, green, cyan, blue, and magenta, before returning to red. 22 ## yellow, green, cyan, blue, and magenta, before returning to red.
23 ## It is useful for displaying periodic functions. The map is obtained by 23 ## It is useful for displaying periodic functions. The map is obtained by
24 ## linearly varying the hue through all possible values while keeping constant 24 ## linearly varying the hue through all possible values while keeping constant
25 ## maximum saturation and value. The equivalent code is 25 ## maximum saturation and value. The equivalent code is
26 ## @code{hsv2rgb ([linspace(0,1,N)', ones(N,2)])}. 26 ## @code{hsv2rgb ([(0:N-1)'/N, ones(N,2)])}.
27 ## 27 ##
28 ## The argument @var{n} must be a scalar. 28 ## The argument @var{n} must be a scalar.
29 ## If unspecified, the length of the current colormap, or 64, is used. 29 ## If unspecified, the length of the current colormap, or 64, is used.
30 ## @seealso{colormap} 30 ## @seealso{colormap}
31 ## @end deftypefn 31 ## @end deftypefn
48 endif 48 endif
49 49
50 if (n == 1) 50 if (n == 1)
51 map = [1, 0, 0]; 51 map = [1, 0, 0];
52 elseif (n > 1) 52 elseif (n > 1)
53 hue = linspace (0, 1, n)'; 53 hue = [0:n-1]' / n;
54 map = hsv2rgb ([hue, ones(n,1), ones(n,1)]); 54 map = hsv2rgb ([hue, ones(n,1), ones(n,1)]);
55 else 55 else
56 map = zeros (0, 3); 56 map = zeros (0, 3);
57 endif 57 endif
58 58