# How to convert 8-bit GrayScale to RGB format (and have it still "look" gray!!!)?

Hello,

I have an image processing app that I am working on and ran into a snag trying to convert from 8-bit grayscale to RGB. The reason I want to do this is so that I can store my image data in the format that I want to use (.XPM).

I noticed alot of people are asking this same question but are coming from the standpoint of wanting to add color to grayscale image. Think Turner broadcast colorization of an old western or something. I don't want this at all. I want my RGB equivalent image to look exactly like my grayscale image.

My input is gray values between 0->FF (0-255).
My output is RGB of the gray value (3 values between 0->FF (0-255))

For example, I know that white is FF in grayscale. After the conversion it should be R=FF, G=FF, B=FF in RBG format. Likewise black is 00: it should be R=00, G=00, B=00. But how do I convert the other 254 values?

Is this possible? Does anyone know the conversion formula?

Thanks!

LVL 3
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
you could set all channels to the same value. So gray E0 would become rgb (E0,E0,E0).
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
GRAY=0.299R + 0.587G + 0.114B
0
Commented:
and (x,x,x) would be a fine solution to that ;)
0
Commented:
Hi rj2,
Wrong conversion direction :-)
0
Commented:
Hi all
sapbucket asked for conversion formula, so I posted conversion formula.
The formula at least demonstrates why gray scale conversion is a one way process. Information is lost about along the way, there are many combinations of R,G,B that satisfies the equation.
0
Author Commented:
Kandura,