Grayscale to Red-Green-Blue (MATLAB Jet) color scale

后端 未结 7 1862
囚心锁ツ
囚心锁ツ 2020-12-12 15:21

I was given a data set that is essentially an image, however each pixel in the image is represented as a value from -1 to 1 inclusive. I am writing an application that need

7条回答
  •  甜味超标
    2020-12-12 15:56

    Java(Processing) code that will generate Jet and HotAndCold RGB. I created this code following the RGB distribution scheme in the post of Amro above.

    color JetColor(float v,float vmin,float vmax){
           float r=0, g=0, b=0;
           float x = (v-vmin)/(vmax-vmin);
           r = 255*constrain(-4*abs(x-0.75) + 1.5,0,1);
           g = 255*constrain(-4*abs(x-0.50) + 1.5,0,1);
           b = 255*constrain(-4*abs(x-0.25) + 1.5,0,1);
           return color(r,g,b);
        }
    
    color HeatColor(float v,float vmin,float vmax){
           float r=0, g=0, b=0;
           float x = (v-vmin)/(vmax-vmin);
           r = 255*constrain(-4*abs(x-0.75) + 2,0,1);
           g = 255*constrain(-4*abs(x-0.50) + 2,0,1);
           b = 255*constrain(-4*abs(x) + 2,0,1);
           return color(r,g,b);
        }
        //Values are calculated on trapezoid cutoff points in format y=constrain(a(x-t)+b,0,1)
        //Where a=((delta)y/(delta)x), t=x-offset value to symetric middle of trapezoid, and b=y-a(x-t) for the last peak point (x,y)
    

提交回复
热议问题