着色灰度图像 [英] Colorize grayscale image

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

问题描述

我有一个灰度图像和一些颜色,用RGB三元组表示。

I have a grayscale image and a some color, represented in RGB triplet. And i need to colorize grayscale image using this triplet.

左边的图片表示我们有什么,我需要什么。
现在在程序中我有一些功能,其中输入是源图像的R,G和B值,以及应该用作着色值的RGB值颜色。
我不能决定如何增加或减少源RGB使用颜色RGB有正确的颜色调色板。

The left image represents what we have and the right what i need to have. Now in program i have some function where in input is R, G and B value of source image and and RGB value color which should be used as coloring value. And i can't decide how can i increase or decrease source RGB using color RGB to have the right color pallette.

语言是C ++,但它是不是那么重要。
提前感谢。

The language is C++, but it's not so important. Thanks in advance.

推荐答案

其他答案建议将灰度值乘以目标RGB颜色。这是好的,但有一个问题,它会改变你的图片的整体亮度。例如,如果你选择一个阴暗的绿色,整个图像将变暗。

The other answers suggest multiplying the grayscale value by the target RGB color. This is okay, but has the problem that it will alter the overall brightness of your picture. For example, if you pick a dark shade of green the whole image will go darker.

我认为RGB颜色模型不是最适合这个。另一种方法是单独选择颜色,而不使用相关的亮度,然后对图像进行着色,同时保留每个像素的原始亮度。

I think the RGB color model is not best suited for this. An alternative would be to pick the color alone, without an associated brightness, then colorize the image while preserving the original brightness of each pixel.

该算法将是这样的:


  • 根据两个值(Hue和饱和度)选择目标颜色。色调决定了颜色(绿色,红色等)的色调,饱和度决定了颜色的纯度(纯度越低,颜色越深变为灰色)。

  • 现在,对于灰度图像中的每个像素,计算HLS颜色模型中的新像素,其中H和S是您的目标色调和饱和度,L是像素的灰度值。

  • 将此HLS颜色转换为RGB并保存到新图片。

对于将HLS转换为RGB的算法,请参阅本页此页

For the algorithm to convert HLS to RGB see this page or this page.

这篇关于着色灰度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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