问题描述
我想将图像更改为Black-White或Sepia。
转换图像后,我想用转换后的图像替换现有图像。
I want to change image to Black-White or Sepia.After converting the image i want to replace the existing image with the converted image.
请给我一些建议。
推荐答案
有很多方法可以去饱和彩色图像。事实上,可能没有一种真实或正确的方法可以做到这一点,尽管某些方式比其他方式更正确。
我假设您的图像是RGB(红绿色) -Blue)格式(虽然BGR也很常见)。
There are many ways to desaturate a color image. In fact, there is probably no one "true" or "correct" way to do it, though some ways are more "correct" than others.
I assume that your image is in RGB (Red-Green-Blue) format (though BGR is also common).
最简单的方式,适用于大多数照片(但对于合成图像来说不太合适),就是使用绿色通道3个RGB通道。人类对光谱的绿色部分的变化最敏感,因此绿色通道覆盖了大部分可见光范围,并且非常接近您想要的灰度图像。
The simplest way, which should work for most photos (but less so for synthetic images), is to just use the Green channel of the 3 RGB channels. Humans are most sensitive to variations in the green part of the spectrum, so the green channel covers most of the visible range and is a good approximation to the grayscale image you want.
生成灰度图像的更好方法是使用3个RGB通道的加权平均值。选择相等的权重(0.33 * R + 0.33 * G + 0.33 * B)将产生非常好的灰度图像。其他凸起的权重(总和为1的非负权重)将给出不同的结果,其中一些可以被认为更美观,并且一些可以考虑感知参数。 (: Y = 0.299 * R + 0.587 * G + 0.114 * B
)
A better way to generate a grayscale image is to use a weighted average of the 3 RGB channels. Choosing equal weights (0.33*R+0.33*G+0.33*B) will give a pretty good grayscale image. Other convex weights (non-negative weights that sum to 1) will give different results some of which may be considered more aesthetically pleasing, and some may take into consideration perceptual parameters. (YUV uses these weights: Y = 0.299*R + 0.587*G + 0.114*B
)
您始终可以将图像转换为另一个只有单的色彩空间灰度通道(和2颜色通道),例如HSV(V是灰度),YUV(Y是灰度)或La b (L是灰度)。差异不应该很大。
You could always convert the image to another color space which has only a single grayscale channel (and 2 "color" channels), such as HSV (V is the grayscale), YUV (Y is the grayscale) or Lab (L is the grayscale). The differences should not be very big.
术语去饱和来自HSV空间。如果您将图像转换为HSV,将S通道(饱和度)设置为全零,并渲染图像,您将获得3通道去饱和颜色图像。
The term "de-saturation" comes from the HSV space. If you convert you image to HSV, set the S channel (Saturation) to be all zeros, and render the image, you will get a 3-channel desaturated "color" image.
将这些灰度通道复制为RGB将为您提供3通道去饱和颜色图像 - 其中所有3个RGB通道都相同。
Duplicating these grayscale channels into RGB will give you a 3-channel desaturated "color" image - where all 3 RGB channels are identical.
一旦你有这个3 -channel(RGB)去饱和图像,您可以将每个通道乘以一个单独的重量来为图像着色 - 一个棕褐色图像。
Once you have this 3-channel (RGB) desaturated image, you can multiply each channel by a seprate weight to colorize the image - a sepia image.
给定灰色像素 [v,v,v]
,将其着色为: [v * a,v * b,v * c]
,这样 0< = a,b,c< = 1
。
Given a gray pixel [v,v,v]
, colorize it like so: [v*a, v*b, v*c]
, such that 0 <= a,b,c <=1
.
这篇关于在c#中将图像转换为黑白或棕褐色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!