RGBtoHSB turns image purple

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

RGBtoHSB turns image purple

Graeme Kidd
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
Reply | Threaded
Open this post in threaded view
|

Re: RGBtoHSB turns image purple

Burger Wilhelm
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
Reply | Threaded
Open this post in threaded view
|

Re: RGBtoHSB turns image purple

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