I want to make a thermal vision like filter effect on a image but I'm a bit stuck.
The gradient goes from Blue->Yellow->Red.
Yellow to Red goes smooth but Blue to Yellow is not smooth with color bumps from green and blue.
This is the effect I want

With my code everything from yellow to red is ok but from blue to yellow goes wrong.
I wrote the method below. What could be the problem?
- Code: Select all
public void thermalVision()
{
size = width * height;
float r, g, b;
float redTemp, yellowTemp, blueTemp;
float luminance = 0;
float result;
index = 0;
redTemp = 0xff000000 | (255 << 16) | (0 << 8) | 0;
yellowTemp = 0xff000000 | (255 << 16) | (255 << 8) | 0;
blueTemp = 0xff000000 | (0 << 16) | (0 << 8) | 255;
while(index < size)
{
r = Color.red(rgbInput[index]);
g = Color.green(rgbInput[index]);
b = Color.blue(rgbInput[index]);
luminance = (float)((float)(r+b+g)/3)/255;
if (luminance < 0.5)
{
luminance = (float) ((luminance*0.5)/0.5);
result = blueTemp *(1-luminance) + yellowTemp * luminance;
}
else
{
luminance = (float) ((luminance-1*0.5)/0.5);
result = yellowTemp *(1-luminance) + redTemp * luminance;
}
output[index] = 0xff000000 | (int) result;
index++;
}

