Skip to main content

Convert image to RGB based on a color ramp

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
10 replies [Last post]
newmanw10
Offline
Joined: 2009-08-17

I am trying to change an Image that has a ComponentSampleModel that has one band (its a float 0.0 - 100.0) into an RGB. I would like to define a color ramp to accomplish this but I am still trying to become familar with the concept.

If I had the color ramp:

0.0 - green

50.0 - brown

100.0 - grey

Is there a way using JAI to convert my single banded image into an RGB using the above ramp?

Thanks in advance!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rafael Santos Guest
Offline
Joined: 2010-11-18

> I am trying to change an Image that has a ComponentColorModel that has one
> band (its a float 0.0 - 100.0) into an RGB.  I would like to define a color
> ramp to accomplish this but I am still trying to become familar with the
> concept.

Not exactly what you need, but it is close:

http://www.lac.inpe.br/JIPCookbook/2200-display-surrogate.jsp#imagedispl...

Rafael

omer_jfm
Offline
Joined: 2011-11-15

Hello All;

As far as i know there is a classification class;

http://jaitools.googlecode.com/svn/branches/1.2-classifiedstats/

here is some details...

for technical background i can say that;

use classification to produce clusters in the image then set the output.

Produce band 1 band 2 band 3 as simple empty frames then fill them with the meaningfull pixel numbers.

This just came to my mind...

Open for discussion...

kind regards

ömer kaya

rgd
Offline
Joined: 2005-08-23

If you want to convert an image to RGB then try the "lookup" operator.
Classification goes the other way (generating a lookup table from a full
color image). Worst case you might have to do the lookup 3 times and
then a bandcombine to make RGB... but lookup might support 3 band output
(don't remember offhand).

-Bob

On 12/14/11 8:22 AM, forums@java.net wrote:
> Hello All;
>
> As far as i know there is a classification class;
>
> http://jaitools.googlecode.com/svn/branches/1.2-classifiedstats/ [1]
>
> here is some details...
>
> for technical background i can say that;
>
> use classification to produce clusters in the image then set the output.
>
> Produce band 1 band 2 band 3 as simple empty frames then fill them with the
> meaningfull pixel numbers.
>
> This just came to my mind...
>
> Open for discussion...
>
> kind regards
>
> ömer kaya
>
>
> [1] http://jaitools.googlecode.com/svn/branches/1.2-classifiedstats/
>

newmanw10
Offline
Joined: 2009-08-17

Does the lookup operator support interpolation?

ie given the ramp

0.0 - green

50.0 - brown

100.0 - grey

how do I lookup the value 42.254354? I am still very new to jai and image processing so a quick example might work wonders.

thanks for your time and patience.

rgd
Offline
Joined: 2005-08-23

There's a "piecewise" operator which does a piecewise linear mapping
which should handle fractional values like that.

But if your result is intended to be byte RGB (such as for display) then
you don't really need the float resolution. You can use the "format"
operator to convert to byte and then do a simple lookup from there. You
can always prescale it so the data range is 0-255 instead of 0-100, then
convert to byte and do the lookup (of course scale the lookup table the
same), so you maximize your color resolution. But for pseudocolor
display (which it sounds like this is), you really don't need more than
8 bits precision - few people can discriminate more and only extremely
rare super-duper-high-end displays support more than 8 bits per channel
anyway.

-Bob

On 12/14/11 10:01 AM, forums@java.net wrote:
> Does the lookup operator support interpolation?
>
> ie given the ramp
>
> 0.0 - green
>
> 50.0 - brown
>
> 100.0 - grey
>
> how do I lookup the value 42.254354? I am still very new to jai and image
> processing so a quick example might work wonders.
>
> thanks for your time and patience.
>
>

newmanw10
Offline
Joined: 2009-08-17

Bob thanks so much for the help but as a newbie, it was way way over my head. I messed around with the lookup operator but no matter what I tried I would always get an exception because my source image was not of an integral type. Ie it is a float for every pixel. You may have hinted on how to solve this but again I am still very confused.

Also and probably most important is that my float values for my pixels range from 0.0 to 1.0. Meaning I cannot used the format operator to cast to a byte as I would lose most of the floats info.

Rafael Santos Guest
Offline
Joined: 2010-11-18

>  Bob thanks so much for the help but as a newbie, it was way way over my
> head. I messed around with the lookup operator but no matter what I tried I
> would always get an exception because my source image was not of an integral
> type. Ie it is a float for every pixel.  You may have hinted on how to
> solve
> this but again I am still very confused. 

(second attempt to help)

The code in
http://www.lac.inpe.br/JIPCookbook/2200-display-surrogate.jsp#imagedispl...
gets a one-band, floating-point image and applies a LUT on it. You can choose
one of several luts or create your own. Code is documented.

Rafael

newmanw10
Offline
Joined: 2009-08-17

Rafael,

Thanks for the reply. I am going to try and apply your example tomorrow. A couple of quick questions.

In your LUTs I see that when you set a color ramp you stay within one band. I.E. blue-yellow. Do you know how I would go about setting up a lookup table for a color ramp that crosses bands. For example blue - red would cross the R and B bands of the image.

I have used the 'lookup' descriptor/operation before and I was intially confused by your code. I don't see a 'lookup' descriptor call but I do see that you change the color map in the rendering hints.

As a correction to my original post my floating point values range from 0.0 - 1.0 not 0 - 100.0. For an easy example for your blue-yellow color ramp where is the magic that says a floating point value of:

0.0 is yellow,

0.5 is half blue, half yellow, and

1.0 is yellow.

Sorry about the confusion I am just trying to understand the code.

Thanks!!

rgd
Offline
Joined: 2005-08-23

Use the "format" operator to convert your image to byte, and then use
lookup. If the range is 0-100 that's probably sufficient and you won't
miss the loss of precision caused by throwing out the fractional part.
If that is an issue, you could remap that to the range 0-255 by using
"multiplyconst" with a factor of (255./100.) and then converting to byte.

-Bob

On 12/14/11 11:02 AM, forums@java.net wrote:
> Bob thanks so much for the help but as a newbie, it was way way over my
> head. I messed around with the lookup operator but no matter what I tried I
> would always get an exception because my source image was not of an
> integral
> type. Ie it is a float for every pixel. You may have hinted on how to
> solve
> this but again I am still very confused.
>
>

newmanw10
Offline
Joined: 2009-08-17

Unfortunatly I am limited to the java api and jai api (if I can even use jai for this type of operation). Looks like your suggestion lives somewhere outside java and jai.

I have searched and searched and I really do not see much in terms of JAI that might be able to help with this type of problem. I am by no means a JAI or image expert so there is a good chance that I am just missing something.

Even if someone has an idea of how to just manipulate the image / create a new image to solve this problem I am all ears as I am really hitting my head against the wall on this one.