Mercurial > hg > octave-lojdl
changeset 16480:3731a1992083
jet.m: Make colormap compatible with Matlab (bug #36473).
* scripts/image/jet.m: Make colormap compatible with Matlab (bug #36473).
author | Rik <rik@octave.org> |
---|---|
date | Tue, 09 Apr 2013 11:37:33 -0700 |
parents | 7a71ea0b7ae9 |
children | 84873dc19757 |
files | scripts/image/jet.m |
diffstat | 1 files changed, 39 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/jet.m +++ b/scripts/image/jet.m @@ -45,17 +45,45 @@ if (n == 1) map = [0, 1, 1]; - 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 >= 3/8 & x < 5/8) .* (-4 * x + 5/2); + elseif (n == 2) + map = [0, 0, 1 + 0, 1, 1]; + elseif (n > 2) + nel = ceil (n/4); # number of elements + idx1 = ceil (3/8 * n) + 1; # ~3/8*n for large n + if (mod (n, 8) == 2) + idx1++; + endif + idx2 = idx1 + nel - 1; # ~5/8*n for large n + idx3 = min (idx2 + nel, n); # ~7/8*n for large n + + r = zeros (n, 1); + r(idx1:idx2, 1) = [1:nel] / nel; + r(idx2:idx3, 1) = 1; + nel2 = n - idx3; + r(idx3:(idx3+nel2), 1) = [nel:-1:(nel - nel2)] / nel; + + idx1 = idx1 - nel; # ~1/8*n for large n + idx2 = idx1 + nel - 1; # ~3/8*n for large n + idx3 = min (idx2 + nel, n); # ~5/8*n for large n + + g = zeros (n, 1); + g(idx1:idx2, 1) = [1:nel] / nel; + g(idx2:idx3, 1) = 1; + nel2 = min (nel, n - idx3); + g(idx3:(idx3+nel2), 1) = [nel:-1:(nel - nel2)] / nel; + + idx1 = max (idx2 - nel, 1); # ~1/8*n for large n + idx2 = idx2; # ~3/8*n for large n + idx3 = idx3; # ~5/8*n for large n + + b = zeros (n, 1); + nel2 = min (nel, idx1-1); + b(1:idx1, 1) = [(nel - nel2):nel] / nel; + b(idx1:idx2, 1) = 1; + nel2 = min (nel, n - idx3); + b(idx2:(idx2+nel2), 1) = [nel:-1:(nel - nel2)] / nel; + map = [r, g, b]; else map = zeros (0, 3);