JuliaAttic / Color.jl

Basic color manipulation utilities.
Other
47 stars 21 forks source link

Colormaps "jet" and "hsv" #75

Open rleegates opened 9 years ago

rleegates commented 9 years ago

Dear Color developers:

Borrowing from MATLAB's colormaps, is it possible to create the colormaps "jet" and "hsv". If so, how could this be done?

Best, Robert

m-lohmann commented 9 years ago

I found the following for the jet color LUT:

http://cresspahl.blogspot.de/2012/03/expanded-control-of-octaves-colormap.html

the r,g,b components of the jet LUT (256 color values) are defined by a simple scheme:


r,g,b=zeros(256),zeros(256),zeros(256)
for i = 0:255
  n=4*i/256
  r[i+1]=255*min(max(min(n-1.5,-n+4.5),0),1);
  g[i+1]=255*min(max(min(n-0.5,-n+3.5),0),1);
  b[i+1]=255*min(max(min(n+0.5,-n+2.5),0),1);
end

I found a list of MATLAB color LUTs here:

http://matlab.izmiran.ru/help/techdoc/ref/colormap.html

hsv seems to be just a variation of the typical rainbow scheme. You can easily build your own if you just work in the HSV color space, define a saturation and value (lightness) and let the hue go from 0 to 360 degrees. If you want to start the rainbow at a different color, just let the hue go from any angle to this angle+360 degrees.

rleegates commented 9 years ago

Thank you very much, I'll have a look at it when I'm back to plotting :)

lobingera commented 9 years ago

Actually both can be done as one-liners:

cm = linspace(Color.HSV(0,1,1),Color.HSV(330,1,1),64)

for HSV, just a linspace in H (0...330). a4

cm = RGB{Float64}[
    RGB(
        clamp(min(4x - 1.5, -4x + 4.5) ,0.0,1.0),
        clamp(min(4x - 0.5, -4x + 3.5) ,0.0,1.0),
        clamp(min(4x + 0.5, -4x + 2.5) ,0.0,1.0))  
    for x in linspace(0.0,1.0,64)]

for jet. I copied this from the Winston source (there is a reference). a5

Maybe a documentation issue.