RGBtoHSB turns image purple

Posted by Graeme Kidd on
URL: http://imagej.273.s1.nabble.com/RGBtoHSB-turns-image-purple-tp3696864.html

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