Java Imaging Help

Hi,

I have problem generating the image with the rainbow colors. Earlier the guy who used to work here mapped the bytes in the file to a redtemperature color table which generates image with the single red color. Now its my work to generate image with rainbow colors. I don't have a color table for the rainbow colors.

Any Help?

[349 byte] By [jonnya] at [2007-10-2 20:20:36]
# 1

> I have problem generating the image with the rainbow colors. Earlier

> the guy who used to work here mapped the bytes in the file to a

> redtemperature color table which generates image with the single

> red color. Now its my work to generate image with rainbow colors. I

> don't have a color table for the rainbow colors.

A trick is to move along the edges of an RGB colour cube from 'cold to hot'.

If you consider 'blue' as cold and 'red' as hot, you should move along

the following edges:

blue --> cyan --> green --> yellow --> red

So basically there are four transitions you should generate in any

number of steps (your choice < 256).

kind regards,

Jos

JosAHa at 2007-7-13 23:02:58 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

I didn't get you completely. Actually the image is a three dimensional image. He is using the following line of code to convert binary image into a value between 0 to 184 to which he has values in redtemperature color table.

int temp = (int) ((data[k][yNum][j] / maxAll) * 184);

After that he draws image using toolkit.

public boolean createXZPanelImage(int yNum, int linePos) {

int[] OneDimImage = new int[rbf4.getNumOfImages() * rbf4.getWidth()];

float[][][] data = rbf4.getPicArray();

float maxAll = rbf4.getMaxAll();

for (int k = 0; k < rbf4.getNumOfImages(); k++) {

for (int j = 0; j < rbf4.getWidth(); j++) {

int temp = (int) ((data[k][yNum][j] / maxAll) * 184);

int col = redTemperatureColor.getColor(temp);

OneDimImage[k * rbf4.getWidth() + j] = col;

}

}

Toolkit tk = Toolkit.getDefaultToolkit();

xzImg = tk.createImage(createMemoryImageSource(rbf4.getWidth(), rbf4

.getNumOfImages(), OneDimImage, 0, rbf4.getWidth()));

iXZPanel.setImage(xzImg);

iXZPanel.repaint();

return true;

}

Now to get rainbow color I think I need to have 256*256*256 values in my color table.

Any examples in this regard is appreciated

jonnya at 2007-7-13 23:02:58 > top of Java-index,Java Essentials,Java Programming...
# 3

You could try mapping your values to the HSB colour space instead of RGB. You get a rainbow if you mantain "saturation" and "brightness" constant and let "hue" go from 0.0 to 1.0. There are several methods for working with HSB in the "Color" class http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Color.html

Mr_Meea at 2007-7-13 23:02:58 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi Mr_Mee,

I tried using HSBtoRGB, the problem is that I am getting red color for hue = 0 brightness = 1 , saturation = 1, but my rainbow should be from

black for hue = 0 and white when hue =1; with VIBGYOR in between.

I chnged Code as

public boolean createXYPanelImage(int imageNum, int linePos) {

int[] OneDimImage = new int[rbf4.getHeight() * rbf4.getWidth()];

float[][][] data = rbf4.getPicArray();

float maxAll = rbf4.getMaxAll();

int horizLine = imageXZSlider.getValue();

for (int k = 0; k < rbf4.getHeight(); k++) {

for (int j = 0; j < rbf4.getWidth(); j++) {

float temp = (float) ((data[imageNum][k][j] / maxAll) * 255);

temp /= 255;

int col = Color.HSBtoRGB(temp, 1, 1);

OneDimImage[k * rbf4.getWidth() + j] = col;

}

}

Toolkit tk = Toolkit.getDefaultToolkit();

xyImg = tk.createImage(createMemoryImageSource(rbf4.getHeight(), rbf4

.getWidth(), OneDimImage, 0, rbf4.getWidth()));

iXYPanel.setImage(xyImg);

iXYPanel.repaint();

return true;

}

Any Help?

jonnya at 2007-7-13 23:02:58 > top of Java-index,Java Essentials,Java Programming...
# 5

eeeh.. but black and white are not colours of the rainbow...? In HSB, Hue is the shade of the colour. Black is any hue with any saturation and 0 brightness. White is any hue with no saturation and full brightness.

You might want to do a linear interpolation between the colours in your list. That way you get the exact sequence you want.

Mr_Meea at 2007-7-13 23:02:58 > top of Java-index,Java Essentials,Java Programming...