问题描述
我想要做的完全一样通过code(机器人)上面的图像。但我困惑的算法来做到这一点。所有我知道的是:
I want to do exactly like the above image via code (android). But I'm confused about the algorithm to do that. All i know is:
随着每一个像素:
-
RGB转换为HSL
Convert RGB to HSL
???
转换HSL回RGB
任何人都可以解释为我做什么,在第2步?非常感谢。
Can anyone explain for me what to do in Step 2? Thanks so much.
PS:(?因为色调和亮度不变)我可以通过ColorMatrix.setSaturation设置饱和度机器人(0),但结果图像不一样的Photoshop
ps: I can set saturation in android via ColorMatrix.setSaturation(0) but the result image not the same as Photoshop (Because the Hue and Lightness not changed?)
推荐答案
您有很多选择去色的图像。另外请注意,在去饱和图像的不可以只是为了让B和; W但对于某些应用程序,你可能会认为他们是相当于
You have many options to desaturate an image.Moreover please note that desaturating an image is not simply to make it B&W but for some applications you may think they're equivalent.
我更新这个帖子有更多的细节。
I updated this post with more details.
这是第一件事的学生的可以做形象转换为灰度(至少是我在过去首先想到的!),但好像饱和度:
This is the first thing a student can image to do to convert to gray scale (at least what I first thought in the past!) and it appears like desaturation:
level = (R + G + B) / 3
它不会产生坏的结果,它的快速和容易实现。但是它有很大的缺陷,它并没有办法的办法人类感知的亮度匹配。
It doesn't produce a bad result, it's fast and easy to implement. But it has the big drawback that it doesn't match the way humans perceive luminosity.
这第二个方法(亮度有时也被称为亮度,亮度或强度)的方式我们的眼睛感知亮度更好的模型。它是基于这样的事实,在眼锥密度是不整个颜色均匀。我们认为绿色要比更强烈的红色和红色更强烈胜于蓝。
因为我们不认为所有的颜色用相同的强度,一般的方法是不准确的(至少看起来不会产生结果的自然的)。如何管理呢?只需使用一个加权平均值:
This second method (Luminance is sometimes called Luminosity, Luma or Intensity) is a better model of the way our eyes perceive brightness. It is based on the fact that cone density in eye is not uniform across colors. We perceive green much more strongly than red and red more strongly than blue.
Because we don't perceive all colors with the same intensity, the average method is inaccurate (at least it doesn't produce a result that looks natural). How to manage this? Simply use a weighted average:
level = R * 0.3 + G * 0.59 + B * 0.11
正如你能想象有很多关于这些价值观的讨论。原ITU-R建议书提出的这个公式:
As you can imagine there are a lot of discussions about these values. Original ITU-R recommendation proposed this formula:
level = R * 0.2126 + G * 0.7152 + B * 0.0722
如果我没看错Photoshop使用这一个为它的简单的饱和功能(是的,这是第一个的圆唇版):
If I'm not wrong Photoshop uses this one for its simple desaturation function (yes, it's the unrounded version of the first one):
level = R * 0.299 + G * 0.587 + B * 0.114
我不认为我们可以注意到一个很大的区别呢reccomandation最近改变了,一起来看看的的维基百科关于这个公式的更多细节。
I don't think we may note a lot of difference anyway reccomandation changed recently, take a look here on Wikipedia for more details about this formula.
你想了解更多的细节?阅读这篇文章,查尔斯Poynton的:伽玛和他的关于这个话题
Do you want more details? Read this article of Charles Poynton: The rehabilitation of gamma and his FAQ about this topic.
您已经但饱和所属的 RGB颜色模型所描述的每个像素=http://en.wikipedia.org/wiki/HSL_and_HSV相对=nofollow> HSL颜色模式(在现实中你可以同时使用HSL或HSV模型时的工作的带饱和)。请阅读链接,有关这些车型的更多细节。
You have each pixel described with the RGB color model but saturation belongs to the HSL color model (in reality you can use both HSL or HSV models when working with saturation). Please read the link for more details about these models.
在去饱和图像由以下步骤:
Desaturating an image consists following steps:
- 在转换每个像素从RGB到HSL(见<一href="http://www.google.com/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=3&ved=0CEAQFjAC&url=http://web2.clarkson.edu/class/image_process/RGB_to_HSI.pdf&ei=ubNtT_CdE_H24QSa__S_Ag&usg=AFQjCNFFJlL1hR6nORlzvVsmlNTJmmDAPg&sig2=w2QIaGmxy5uQSHp_wxJhGA"相对=nofollow>这篇文章如果你需要详细信息)。
- 强制饱和度为零(这应该是什么
setSaturation(0)
一样) - 将其转换回RGB(见本书签)。
- Convert each pixel from RGB to HSL (see this article if you need details).
- Force the saturation to zero (this should be what
setSaturation(0)
does) - Convert it back to RGB (see this bookmark).
我来介绍一下在这个过程中的大的semplification:你可以去色色发现RGB的最大值和最小值的RGB(亮度之间的中点,你还记得那一种颜色,在 RGB色空间时,是在三维空间中的点?)。 (简化)公式得到降低饱和度图像:
Let me introduce a big semplification on this process: you can desaturate a color finding the midpoint between the maximum of RGB and the minimum of RGB (lightness, do you remember that a color, in the RGB color space, is a point in the 3D space?). The (simplified) formula to get the desaturated image is:
level = (max(R, G, B) + min(R, G, B)) / 2
德组成
一个简单的形式去饱和,有时也被称为的本地最大的分解的只是挑选每个RGB三元组的最高值:
De-composition
A simpler form of desaturation, called sometimes local maximal decomposition simply picks the maximum value of each RGB triplet:
level = max(R, G, B);
正如你可以想像,你可以同时使用当地最大或局部最小(我写的本地的,因为它的最小搜索/最大值每个像素)。
As you can imagine you can use both local maximum or local minimum (I wrote local because it searches the minimum/maximum for each pixel).
不要忘记,你可以得到一个B和用黑白(当时东西,看起来像一个去饱和的图像)在一个非常快速的方式简单地保持一个单独的通道从RGB三元组(如绿色通道),并复制该值到所有通道)。
有时Photoshops教程不使用其功能去色的图像(去色功能和调节面板),但要取得更好的成绩,他们加了一层具有统一的颜色(与值计算的亮度的部分)和他们合并层与原始图像(搜索教程,并摄制在code,步骤)。
Do not forget that you can get a B&W image (then something that looks like a desaturated image) in a very fast way simply keeping one single channel from the RGB triplet (for example the green channel) and copying that value to all channels).
Sometimes Photoshops tutorials don't use its functions to desaturate an image (the Desaturate function and the Adjustment palette) but to achieve better results they add a layer with a uniform color (calculated with values from Luminance section) and the they merge that layer with the original image (search for a tutorial and repro that steps in your code).
这篇关于如何将图像转换为灰度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!