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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/autumn.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/bone.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/cool.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/copper.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/flag.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/gmap40.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/gray.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/hot.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/hsv.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/jet.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/lines.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/ocean.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/pink.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/prism.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/rainbow.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/spring.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/summer.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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 = [];
--- a/scripts/image/white.m	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/white.m	Sat Jan 28 22:33:57 2012 -0800
@@ -39,11 +39,7 @@
     print_usage ();
   endif
 
-  if (n > 0)
-    map = ones (n, 3);
-  else
-    map = [];
-  endif
+  map = ones (n, 3);
 
 endfunction
 
--- a/scripts/image/winter.m	Sun Jan 29 00:52:19 2012 -0500
+++ b/scripts/image/winter.m	Sat Jan 28 22:33:57 2012 -0800
@@ -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 = [];