Mercurial > hg > octave-terminal
changeset 14279:f205d0074687
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.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 28 Jan 2012 22:33:57 -0800 |
parents | fa894f89b18f |
children | fd8b8f0f68b9 |
files | scripts/image/autumn.m scripts/image/bone.m scripts/image/cool.m scripts/image/copper.m scripts/image/flag.m scripts/image/gmap40.m scripts/image/gray.m scripts/image/hot.m scripts/image/hsv.m scripts/image/jet.m scripts/image/lines.m scripts/image/ocean.m scripts/image/pink.m scripts/image/prism.m scripts/image/rainbow.m scripts/image/spring.m scripts/image/summer.m scripts/image/white.m scripts/image/winter.m |
diffstat | 19 files changed, 62 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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];
--- 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];
--- 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
--- 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
--- 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
--- 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 = [];
--- 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
--- 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
--- 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
--- 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
--- 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 = [];
--- 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
--- 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 = [];
--- 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
--- a/scripts/image/summer.m +++ b/scripts/image/summer.m @@ -27,6 +27,7 @@ ## Author: Kai Habel <kai.habel@gmx.de> ## 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 = [];