# Thread: Pixel color conversion question!

1. ## Pixel color conversion question!

Hello,

If we have a full green pixel with the RGB weight of:

00 - 128 - 00

and we want to convert it to its equivalent red shade, we agree that the red pixel would be a full red RGB weight of:

255 - 00 - 00

But what if the green pixel wasn't exactly of a pure green. Say it was:

01 - 128 - 01

What would its red color equivalent be???

rob

2. I don't know that there is any exact "equivalent color", to any color, in another color. Maybe what you want to do is to swap the green and the red values, in your example, and leave the blue value alone.

Your question is like asking what even number is equivalent to 3? It just doesn't have an answer.

3. Originally Posted by see the big C
Hello,

If we have a full green pixel with the RGB weight of:

00 - 128 - 00

and we want to convert it to its equivalent red shade, we agree that the red pixel would be a full red RGB weight of:

255 - 00 - 00

But what if the green pixel wasn't exactly of a pure green. Say it was:

01 - 128 - 01

What would its red color equivalent be???

rob
Who is "we"? In my opinion, the equivalent shade of red would be 128 - 00 - 00 because 50% green would instead become 50% red.

As for your question, it depends on what your actual colour transformation is supposed to be. Is it supposed to simply swap the red and green, or rotate green -> red -> blue, or something else?
You need to explain more about what you actually want.

4. hello iMalc,

>Who is "we"? In my opinion, the equivalent shade of red would be 128 - 00 - 00 because 50% >green would instead become 50% red.

Impossible... it can't be that simple. Lets reason this a little. If we want to recolor a pixel from green to red. We are actually saying that we want a value that equates the real raw green color *shade* to the real raw red color *shade*. So:

Real raw green to real raw red is:

00-128-00 to 255-00-00

which is the real color substitution. If you want to recolor a green pixel to a red one and you do this:

00-128-00 to 128-00-00

then 128-00-00 is not the real raw genuine red shade? Its just a darker red! Which in visual contrast is wrong.

What I am trying to do, is recolor an image. Suppose we have a greenish square with multiple shades of green in it and I want to recolor this square to a reddish color. So if a green pixel exists in the green square I want it to be red in the red square. If a lighter green pixel exists in the green square I want a proportionally lighter red pixle in the red square.

Anyways, I copied a green square from MS Paint to MS publisher and then converted it in MSPublisher and gave me the following results... Now I am really confused!!!

Paint green: 00-128-00
Converted to red in MSPublisgher : 255-92-92
????

rob

5. Why is "real raw green" 128? Why isn't "real raw green" 255?

6. Because according to any bitmap editor:

00-255-00

is expressed as "Lime" and not green ????

R

7. If I take looots of snow, as much as I can, it's not snow anymore.

If I take looots of green, as much as I can, it's lime, not green.

EDIT: And by the way, at least all the limes I've seen are green.

8. If we have a full green pixel with the RGB weight of:

00 - 128 - 00
I wouldn't say that's full green. Sure, there is only green, but it's at half intensity. Logically, half green should map to half red.

Because according to any bitmap editor:

00-255-00

is expressed as "Lime" and not green ????
That's just a name for that shade of green, probably given by some programmer. Regardless of the names given to those RGB values, they are both pure greens, just of a different shades. There is no red or blue in either of those colors.

For colors composed of more than one of R, G or B values, you could always try converting it to an HSL/HSV model and rotating your color by some number of degrees (+/- 120 probably). You can then convert it back if you still need RGB values.

9. Originally Posted by see the big C
Hello,

If we have a full green pixel with the RGB weight of:

00 - 128 - 00

and we want to convert it to its equivalent red shade, we agree that the red pixel would be a full red RGB weight of:

255 - 00 - 00

But what if the green pixel wasn't exactly of a pure green. Say it was:

01 - 128 - 01

What would its red color equivalent be???

rob
RGB is not the best color space for those types of conversions. I'd recommend using something like HSV, personally - selecting "similar" colors is almost trivial...

10. >If I take looots of green, as much as I can, it's lime, not green.

I know what you are saying .. its just find it weird that if I have a greenish color stop sign and I want recolor it reddish, I get it marooninsh!!!!

r

11. Originally Posted by see the big C
its just find it weird that if I have a greenish color stop sign and I want recolor it reddish, I get it marooninsh!!!!
That's probably because the human eye is far more sensitive to green colors than red (or any other wavelength of light). Green light (around 550nm) is close to the peak radiation that our sun puts off, which is probably why we evolved to see green best, and why plants are green, etc. Red and blue lie on the outer edges of our visual spectrum, and we can not distinguish shades of red or blue as well as we can green. I had a set of color gradients that showed this very well, but they were from a class a decade ago...

12. Originally Posted by see the big C
>If I take looots of green, as much as I can, it's lime, not green.

I know what you are saying .. its just find it weird that if I have a greenish color stop sign and I want recolor it reddish, I get it marooninsh!!!!

r
Well, RGB was designed for display monitors; it's relationship to our perception of color is a rather unnatural one!

13. anduril462 ,

I suppose so.

14. Okay sure, you're interested in maintaining percieved brighteness. One source I knew of on wikipedia, has the following for a function of perceived brightness:
30% of the red value, 59% of the green value, and 11% of the blue value
You're right that this puts red at close to half the perceived brightness of green.

However, there are still things to consider. How light of a green would you still want to convert to red? For example, would you want to convert 254 - 255 - 254 to something like 255 - 254 - 254 ?
Note that I can't yet tell what you want to do with the existing red channel. For the conversions any of us have thought of so far, it looks like swapping (and scaling) the red and green components would work.
A formula comes to mind:
Code:
```NewRed = max(OldGreen * 59 / 30, 255);
NewGreen = OldRed * 30 / 59;```
Now, how well does this do for you? What does it do that is not desireable such that we can tweak it further (or replace it)?
Byt the way, what were you wanting to do with pixels that were already reddish?

15. Originally Posted by anduril462
That's probably because the human eye is far more sensitive to green colors than red (or any other wavelength of light). Green light (around 550nm) is close to the peak radiation that our sun puts off, which is probably why we evolved to see green best, and why plants are green, etc.
I've always thought this was weird. The sun does put out the most light near green, and yet plants, which use sunlight to produce food, most strongly REFLECT this portion of the spectrum. A plant that absorbed most strongly in green would have a color more like magenta. Why don't we have magenta plants?

EDIT: The OP can probably accomplish his goal by converting from RGB to HSV, selecting pixels with H in a "close enough" range of green, and rotate the H coordinate into the red region, then convert back to RGB.

Note that RGB is a really, really crappy color space to be working in. It's device-dependent and has no standard definition.