0
votes

I want to color gray-scale image with only one color. So I have for example pixel: RGB(34,34,34) and I want to color it with color: RGB(200,100,50) to get new RGB pixel. So I new to do this for every pixel in image.

The white pixels get color: RGB(200,100,50), darker pixels get darker color than RGB(200,100,50).

So the result is gray-scale with black and selected color instead of black and white.

I will program this hard core without any built in function.

Similar to this: Image or this:Image

2

2 Answers

1
votes

All you need to do is use the ratio of gray to white as a multiplier to your color. I think you'll find that this gives better results than a blend.

new_red = gray * target_red / 255
new_green = gray * target_green / 255
new_blue = gray * target_blue / 255
2
votes

From what you describe I figure you look for a blending algorithm.

What you need is a blendingPercentage (bP).

new red = red1 * bP + red2 * (1 - bP)
new green = green1 * bP + green2 * (1 - bP)
new blue = blue1 * bP + blue2 * (1 - bP)

Your base color is RGB 34 34 34; Color to blend is RGB 200 100 50
BlendingPercentage for example = 50% -> 0.5

Therefore:
New red = 34 * 0.5 + 200 * (1 - 0.5) = 117
New green = 34 * 0.5 + 100 * (1 - 0.5) = 67
New blue = 34 * 0.5 + 50 * (1 - 0.5) = 42