changeset 16439:7762d56dbc8a

pink.m: Make colormap compatible with Matlab (bug #36473). * scripts/image/pink.m: Make colormap compatible with Matlab (bug #36473).
author Rik <rik@octave.org>
date Fri, 05 Apr 2013 16:21:38 -0700
parents a971d8bdaadc
children aaf024ac8015
files scripts/image/pink.m
diffstat 1 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/pink.m	Fri Apr 05 03:04:56 2013 -0400
+++ b/scripts/image/pink.m	Fri Apr 05 16:21:38 2013 -0700
@@ -45,15 +45,34 @@
 
   if (n == 1)
     map = sqrt ([1/3, 1/3, 1/3]);
-  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) ...
-      + (x >= 3/4) .* (2/3 * x + 1/3);
-    b = (x < 3/4) .* (2/3 * x) ...
-      + (x >= 3/4) .* (2 * x - 1);
+  elseif (n == 2)
+    map = sqrt ([1/3, 1/3, 1/6
+                  1    1    1 ]);
+  elseif (n > 2)
+    x = [0:(n-1)]' / (n-1);
+    idx = floor (3/8 * n);
+    base = floor (n/8);
+    switch (mod (n, 8))
+      case {0, 1, 2}
+        base = 1 / (9*base);
+      case {3, 4, 5}
+        base = 1 / (9*base + 3);
+      case {6, 7}
+        base = 1 / (9*base + 6);
+    endswitch
+
+    nel = idx;   # number of elements
+    r(1:idx,1) = linspace (base, 2/3*x(idx) + 1/3, nel);
+    r(idx+1:n,1) = 2/3*x(idx+1:n) + 1/3;
+
+    g(1:idx,1) = 2/3*x(1:idx);
+    g(idx:2*idx,1) = linspace (2/3*x(idx), 2/3*x(2*idx) + 1/3, nel+1);
+    g(2*idx+1:n,1) = 2/3*x(2*idx+1:n) + 1/3;
+
+    nel = n - 2*idx + 1;
+    b(1:2*idx,1) = 2/3*x(1:2*idx);
+    b(2*idx:n,1) = linspace (2/3*x(2*idx), 1, nel);
+
     map = sqrt ([r, g, b]);
   else
     map = zeros (0, 3);