在灰度图象的颜色 [英] Color over grayscale image

查看:220
本文介绍了在灰度图象的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一种颜色来着色灰度图像。所以我有例如像素: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆