Re: RGBtoHSB turns image purple

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

Thanks Wilhelm,
Thought it would be something silly.

--------------------------------------------------
From: "Burger Wilhelm" <[hidden email]>
Sent: Sunday, March 16, 2008 12:21 PM
To: <[hidden email]>
Subject: Re: RGBtoHSB turns image purple

> 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
>