The extraction of the green component is wrong:
int g = (c & 0x0000ff)>>8;
should be
int g = (c & 0x00ff00)>>8;
instead.
Wilhelm
________________________________
Von: ImageJ Interest Group im Auftrag von Graeme Kidd
Gesendet: So 16.03.2008 12:38
An:
[hidden email]
Betreff: RGBtoHSB turns image purple
I am currently using HSBtoRGB and RGBtoHSB from Java's color class but I am having a problem. This simple example should produce the same image but instead it adds a hint of purple.
int pos = offset+j;
int c = pixels[pos];
int r = (c & 0xff0000)>>16;
int g = (c & 0x0000ff)>>8;
int b = (c & 0x0000ff);
float hsbVal[] = new float[3];
Color.RGBtoHSB(r, g, b, hsbVal);
pixels[pos] = Color.HSBtoRGB( hsbVal[0], hsbVal[1], hsbVal[2]);
Any ideas what I am doing wrong?
Thanks