在灰度图象的颜色 [英] Color over grayscale image
问题描述
我想用一种颜色来着色灰度图像。所以我有例如像素:RGB(34,34,34),我想用颜色:RGB(200,100,50)来获得新的RGB像素。所以我新的做这个为图像中的每个像素。
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.
白色像素获得颜色:RGB(200,100,50),较暗的像素的颜色比RGB(200,100,50)的颜色深。
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.
推荐答案
全部你需要做的是使用灰色与白色的比率作为你的颜色的乘数。我想你会发现,这比混合使用更好的结果。
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
这篇关于在灰度图象的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!