# HG changeset patch # User Rik # Date 1327818837 28800 # Node ID f205d0074687464d4af356d9e34ef66f83f2fd1b # Parent fa894f89b18f4a51293b258ca7b4ef72cb6a974d Update colormap files with faster code. * autumn.m, bone.m, cool.m, copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, jet.m, lines.m, ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m: Use indexing in place of kron or repmat for faster code. diff --git a/scripts/image/autumn.m b/scripts/image/autumn.m --- a/scripts/image/autumn.m +++ b/scripts/image/autumn.m @@ -44,7 +44,7 @@ map = [1, 0, 0]; elseif (n > 1) r = ones (n, 1); - g = (0:n - 1)' ./ (n - 1); + g = [0:(n-1)]' / (n - 1); b = zeros (n, 1); map = [r, g, b]; else diff --git a/scripts/image/bone.m b/scripts/image/bone.m --- a/scripts/image/bone.m +++ b/scripts/image/bone.m @@ -44,16 +44,18 @@ map = [0, 0, 0]; elseif (n > 1) x = linspace (0, 1, n)'; - - r = (x < 3/4) .* (7/8 * x) + (x >= 3/4) .* (11/8 * x - 3/8); - g = (x < 3/8) .* (7/8 * x)\ - + (x >= 3/8 & x < 3/4) .* (29/24 * x - 1/8)\ + r = (x < 3/4) .* (7/8 * x) ... + + (x >= 3/4) .* (11/8 * x - 3/8); + g = (x < 3/8) .* (7/8 * x) ... + + (x >= 3/8 & x < 3/4) .* (29/24 * x - 1/8) ... + (x >= 3/4) .* (7/8 * x + 1/8); - b = (x < 3/8) .* (29/24 * x) + (x >= 3/8) .* (7/8 * x + 1/8); + b = (x < 3/8) .* (29/24 * x) ... + + (x >= 3/8) .* (7/8 * x + 1/8); map = [r, g, b]; else map = []; endif + endfunction diff --git a/scripts/image/cool.m b/scripts/image/cool.m --- a/scripts/image/cool.m +++ b/scripts/image/cool.m @@ -42,7 +42,7 @@ if (n == 1) map = [0, 1, 1]; elseif (n > 1) - r = (0:n - 1)' ./ (n - 1); + r = [0:(n-1)]' / (n - 1); g = 1 - r; b = ones (n, 1); map = [r, g, b]; diff --git a/scripts/image/copper.m b/scripts/image/copper.m --- a/scripts/image/copper.m +++ b/scripts/image/copper.m @@ -44,7 +44,8 @@ map = [0, 0, 0]; elseif (n > 1) x = linspace (0, 1, n)'; - r = (x < 4/5) .* (5/4 * x) + (x >= 4/5); + r = (x < 4/5) .* (5/4 * x) ... + + (x >= 4/5); g = 4/5 * x; b = 1/2 * x; map = [r, g, b]; diff --git a/scripts/image/flag.m b/scripts/image/flag.m --- a/scripts/image/flag.m +++ b/scripts/image/flag.m @@ -40,14 +40,8 @@ print_usage (); endif - p = [1, 0, 0; 1, 1, 1; 0, 0, 1; 0, 0, 0]; - if (rem(n,4) == 0) - map = kron (ones (n / 4, 1), p); - else - m1 = kron (ones (fix (n / 4), 1), p); - m2 = p(1:rem (n, 4), :); - map = [m1; m2]; - endif + C = [1, 0, 0; 1, 1, 1; 0, 0, 1; 0, 0, 0]; + map = C(rem (0:(n-1), 4) + 1, :); endfunction diff --git a/scripts/image/gmap40.m b/scripts/image/gmap40.m --- a/scripts/image/gmap40.m +++ b/scripts/image/gmap40.m @@ -40,12 +40,8 @@ print_usage (); endif - if (n >= 1) - map = repmat ([1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1], - ceil (n / 6), 1) (1:n, :); - else - map = []; - endif + C = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1]; + map = C(rem (0:(n-1), 6) + 1, :); endfunction diff --git a/scripts/image/gray.m b/scripts/image/gray.m --- a/scripts/image/gray.m +++ b/scripts/image/gray.m @@ -42,9 +42,9 @@ print_usage (); endif - gr = [0:(n-1)]'; + gr = [0:(n-1)]' / (n - 1); - map = [ gr, gr, gr ] / (n - 1); + map = [gr, gr, gr]; endfunction diff --git a/scripts/image/hot.m b/scripts/image/hot.m --- a/scripts/image/hot.m +++ b/scripts/image/hot.m @@ -44,9 +44,11 @@ map = [0, 0, 0]; elseif (n > 1) x = linspace (0, 1, n)'; - r = (x < 2/5) .* (5/2 * x) + (x >= 2/5); - g = (x >= 2/5 & x < 4/5) .* (5/2 * x - 1) + (x >= 4/5); - b = (x >= 4/5) .* (5*x - 4); + r = (x < 2/5) .* (5/2 * x) ... + + (x >= 2/5); + g = (x >= 2/5 & x < 4/5) .* (5/2 * x - 1) ... + + (x >= 4/5); + b = (x >= 4/5) .* (5 * x - 4); map = [r, g, b]; else map = []; diff --git a/scripts/image/hsv.m b/scripts/image/hsv.m --- a/scripts/image/hsv.m +++ b/scripts/image/hsv.m @@ -20,9 +20,9 @@ ## @deftypefn {Function File} {} hsv (@var{n}) ## Create color colormap. This colormap begins with red, changes through ## yellow, green, cyan, blue, and magenta, before returning to red. -## It is useful for displaying periodic functions. It is obtained by linearly -## varying the hue through all possible values while keeping constant maximum -## saturation and value and is equivalent to +## It is useful for displaying periodic functions. The map is obtained by +## linearly varying the hue through all possible values while keeping constant +## maximum saturation and value. The equivalent code is ## @code{hsv2rgb ([linspace(0,1,N)', ones(N,2)])}. ## ## The argument @var{n} must be a scalar. @@ -47,8 +47,8 @@ if (n == 1) map = [1, 0, 0]; elseif (n > 1) - h = linspace (0, 1, n)'; - map = hsv2rgb ([h, ones(n, 1), ones(n, 1)]); + hue = linspace (0, 1, n)'; + map = hsv2rgb ([hue, ones(n,1), ones(n,1)]); else map = []; endif diff --git a/scripts/image/jet.m b/scripts/image/jet.m --- a/scripts/image/jet.m +++ b/scripts/image/jet.m @@ -43,12 +43,15 @@ if (n == 1) map = [0, 0, 0.5]; elseif (n > 1) - x = linspace(0, 1, n)'; - r = (x >= 3/8 & x < 5/8) .* (4 * x - 3/2)\ - + (x >= 5/8 & x < 7/8) + (x >= 7/8) .* (-4 * x + 9/2); - g = (x >= 1/8 & x < 3/8) .* (4 * x - 1/2)\ - + (x >= 3/8 & x < 5/8) + (x >= 5/8 & x < 7/8) .* (-4 * x + 7/2); - b = (x < 1/8) .* (4 * x + 1/2) + (x >= 1/8 & x < 3/8)\ + x = linspace (0, 1, n)'; + r = (x >= 3/8 & x < 5/8) .* (4 * x - 3/2) ... + + (x >= 5/8 & x < 7/8) ... + + (x >= 7/8) .* (-4 * x + 9/2); + g = (x >= 1/8 & x < 3/8) .* (4 * x - 1/2) ... + + (x >= 3/8 & x < 5/8) ... + + (x >= 5/8 & x < 7/8) .* (-4 * x + 7/2); + b = (x < 1/8) .* (4 * x + 1/2) ... + + (x >= 1/8 & x < 3/8) ... + (x >= 3/8 & x < 5/8) .* (-4 * x + 5/2); map = [r, g, b]; else diff --git a/scripts/image/lines.m b/scripts/image/lines.m --- a/scripts/image/lines.m +++ b/scripts/image/lines.m @@ -39,9 +39,9 @@ print_usage (); endif - c = get (gca, "colororder"); - nr = rows (c); - map = c(rem (0:(n-1), nr) + 1, :); + C = get (gca, "colororder"); + nr = rows (C); + map = C(rem (0:(n-1), nr) + 1, :); endfunction diff --git a/scripts/image/ocean.m b/scripts/image/ocean.m --- a/scripts/image/ocean.m +++ b/scripts/image/ocean.m @@ -45,16 +45,14 @@ cutin = fix (n/3); dr = (n - 1) / cutin; - r = prepad ([0:dr:(n-1)], n)'; dg = (n - 1) / (2 * cutin); - - g = prepad([0:dg:(n-1)], n)'; + g = prepad ([0:dg:(n-1)], n)'; b = [0:(n-1)]'; - map = [ r, g, b ] / (n - 1); + map = [r, g, b] / (n - 1); endfunction diff --git a/scripts/image/pink.m b/scripts/image/pink.m --- a/scripts/image/pink.m +++ b/scripts/image/pink.m @@ -44,12 +44,13 @@ map = [0, 0, 0]; elseif (n > 1) x = linspace (0, 1, n)'; - r = (x < 3/8) .* (14/9 * x) + (x >= 3/8) .* (2/3 * x + 1/3); - g = (x < 3/8) .* (2/3 * x)\ - + (x >= 3/8 & x < 3/4) .* (14/9 * x - 1/3)\ + r = (x < 3/8) .* (14/9 * x) ... + + (x >= 3/8) .* (2/3 * x + 1/3); + g = (x < 3/8) .* (2/3 * x) ... + + (x >= 3/8 & x < 3/4) .* (14/9 * x - 1/3) ... + (x >= 3/4) .* (2/3 * x + 1/3); - b = (x < 3/4) .* (2/3 * x) + (x >= 3/4) .* (2 * x - 1); - + b = (x < 3/4) .* (2/3 * x) ... + + (x >= 3/4) .* (2 * x - 1); map = sqrt ([r, g, b]); else map = []; diff --git a/scripts/image/prism.m b/scripts/image/prism.m --- a/scripts/image/prism.m +++ b/scripts/image/prism.m @@ -40,9 +40,8 @@ print_usage (); endif - p = [1, 0, 0; 1, 1/2, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 2/3, 0, 1]; - - map = [repmat(p, fix(n/6), 1); p(1:rem (n, 6), :)]; + C = [1, 0, 0; 1, 1/2, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 2/3, 0, 1]; + map = C(rem (0:(n-1), 6) + 1, :); endfunction diff --git a/scripts/image/rainbow.m b/scripts/image/rainbow.m --- a/scripts/image/rainbow.m +++ b/scripts/image/rainbow.m @@ -47,11 +47,14 @@ map = [1, 0, 0]; elseif (n > 1) x = linspace (0, 1, n)'; - r = (x < 2/5) + (x >= 2/5 & x < 3/5) .* (-5 * x + 3)\ + r = (x < 2/5) ... + + (x >= 2/5 & x < 3/5) .* (-5 * x + 3) ... + (x >= 4/5) .* (10/3 * x - 8/3); - g = (x < 2/5) .* (5/2 * x) + (x >= 2/5 & x < 3/5)\ + g = (x < 2/5) .* (5/2 * x) ... + + (x >= 2/5 & x < 3/5) ... + (x >= 3/5 & x < 4/5) .* (-5 * x + 4); - b = (x >= 3/5 & x < 4/5) .* (5 * x - 3) + (x >= 4/5); + b = (x >= 3/5 & x < 4/5) .* (5 * x - 3) + + (x >= 4/5); map = [r, g, b]; else map = []; diff --git a/scripts/image/spring.m b/scripts/image/spring.m --- a/scripts/image/spring.m +++ b/scripts/image/spring.m @@ -43,7 +43,7 @@ map = [1, 0, 1]; elseif (n > 1) r = ones (n, 1); - g = (0:n - 1)' ./ (n - 1); + g = [0:(n-1)]' / (n - 1); b = 1 - g; map = [r, g, b]; else diff --git a/scripts/image/summer.m b/scripts/image/summer.m --- a/scripts/image/summer.m +++ b/scripts/image/summer.m @@ -27,6 +27,7 @@ ## Author: Kai Habel ## Date: 06/03/2000 + function map = summer (n) if (nargin == 0) @@ -42,10 +43,9 @@ if (n == 1) map = [0, 0.5, 0.4]; elseif (n > 1) - r = (0:n - 1)' ./ (n - 1); - g = 0.5 + r ./ 2; + r = [0:(n-1)]' / (n - 1); + g = 0.5 + r / 2; b = 0.4 * ones (n, 1); - map = [r, g, b]; else map = []; diff --git a/scripts/image/white.m b/scripts/image/white.m --- a/scripts/image/white.m +++ b/scripts/image/white.m @@ -39,11 +39,7 @@ print_usage (); endif - if (n > 0) - map = ones (n, 3); - else - map = []; - endif + map = ones (n, 3); endfunction diff --git a/scripts/image/winter.m b/scripts/image/winter.m --- a/scripts/image/winter.m +++ b/scripts/image/winter.m @@ -43,9 +43,8 @@ map = [0, 0, 1]; elseif (n > 1) r = zeros (n, 1); - g = (0:n - 1)' ./ (n - 1); - b = 1 - g ./ 2; - + g = [0:(n-1)]' / (n - 1); + b = 1 - g / 2; map = [r, g, b]; else map = [];