Skip to main content

Convert image to RGB based on a color ramp (attempt #2)

5 replies [Last post]
newmanw10
Offline
Joined: 2009-08-17
Points: 0

I am trying to change an Image that has a FloatDoubleColorModel that has one band (its a float 0.0 - 1.0) into a three band RGB. Please not that the range is 0.0 - 1.0 not 0.0 - 100.0

I would like to define a color ramp to accomplish this. For simplicity sake I am just trying to go from blue to yellow.

Rafael I have tried your approach (http://www.lac.inpe.br/JIPCookbook/2200-display-surrogate.jsp#imagedispl...) with no luck. I used the blue to yellow lut and the resulting image came back as all blue. I have verified my images range is indeed between 0.0 and 1.0. If there is anything else I can tell you to help solve the problem please ask.

In debugging I have noticed that the images color model is a FloatDoubleColorModel. Not really sure if that makes a difference or not.

Anyone have any ideas on things I can try.

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
newmanw10
Offline
Joined: 2009-08-17
Points: 0

Rafael, sorry I had a bug in code that was causing the all blue image. I got it working and blue to yellow works great. Thanks so much for your help.

I do still have a question about creating a lookup table based on two (or more users defined colors).

i.e. if the user picks

0.0 - blue(0x0000FF)

1.0 - red(0xFF0000)

Is there a way to create a lookup table for those values?

Rafael Santos Guest
Offline
Joined: 2010-11-18
Points: 0

>
> Rafael I have tried your approach
> (http://www.lac.inpe.br/JIPCookbook/2200-display-surrogate.jsp#imagedispl...
> [1]) with no luck.

Define "no luck". Some people used the cleverly hidden hints in my code to win
the lottery and are billionaires now :-)

Note that the code linearly stretches the image from (min,max) to (0.255) then
convert it to an integer image then use a LUT with these values from 0 to 255 as
indexes.

>  I used the blue to yellow lut and the resulting image
> came back as all blue.  I have verified my images range is indeed between
> 0.0 and 1.0.  If there is anything else I can tell you to help solve the
> problem please ask.

Suppose your image pixels' values are from 0.0 to 1.0, but the vast majority of
those are between 0.0 and 0.001 -- you will have to scale them in a different way.
Check your image's histogram to see if there are values close to 1.0.

Rafael

newmanw10
Offline
Joined: 2009-08-17
Points: 0

Rafael, yeah sorry please see above post I did have a bug. I am still trying to wrap my head around defining a map based on a start color and end color.

0.0 = 0x0000FF (blue)

1.0 = 0xFF0000 (red)

Thanks again for the help!

rgd
Offline
Joined: 2005-08-23
Points: 0

Here's a simple way to do the color map. Say the RGB value of the start
color is R1,G1,B1 and for the end is R2,G2,B2. Make 3 arrays of 256
elements, one array for each color band. Then linearly interpolate the
values in the array from one endpoint to the other. Something like:

for (i=0; i<256; i++) {
r[i] = r1 + (r2-r1)*(i/256.);
... same for g,b
}

It might not go through the intermediate colors you want but it'll do
something. If you want to go through other colors, put them in at the
appropriate spot and simply linearly interpolate between the colors you
have.

-Bob

On 12/15/11 9:59 AM, forums@java.net wrote:
> Rafael, yeah sorry please see above post I did have a bug. I am still
> trying to wrap my head around defining a map based on a start color and end
> color.
>
> 0.0 = 0x0000FF (blue)
>
> 1.0 = 0xFF0000 (red)
>
> Thanks again for the help!
>
>
>
>

Rafael Santos Guest
Offline
Joined: 2010-11-18
Points: 0

>  Rafael, yeah sorry please see above post I did have a bug. I am still
> trying to wrap my head around defining a map based on a start color and end
> color. 
>
> 0.0 = 0x0000FF (blue)
>
> 1.0 = 0xFF0000 (red)

It depends on what you want to have in the intermediate values.
Take at look at some pictures at http://en.wikipedia.org/wiki/HSL_and_HSV
There are several ways to trace a line from blue to red.

The simplest way would have to create a linear interpolator between red and
blue. Depending on the endpoints the middle colors will be just an ugly blur.

Rafael

public class LUT
{
public static void main(String[] args)
{
int[] fromColor = new int[]{0,0,255};
int[] toColor = new int[]{255,0,0};
int steps = 256;
float[] deltas = new float[3];
for(int d=0;d<3;d++)
deltas[d] = (toColor[d]-fromColor[d])/(1f*(steps-1));
for(int s=0;s