将灰度值转换为 RGB 表示形式?

发布于 2024-07-19 07:10:42 字数 237 浏览 3 评论 0原文

如何将灰度值 (0-255) 转换为 RGB 值/表示形式? 它用于在 SVG 图像中使用,该图像似乎没有灰度支持,只有 RGB...

注意:这不是 RGB -> 灰度,这已经在另一个问题中得到了回答,例如 将 RGB 转换为灰度/强度

How can I convert a grayscale value (0-255) to an RGB value/representation?
It is for using in an SVG image, which doesn't seem to come with a grayscale support, only RGB...

Note: this is not RGB -> grayscale, which is already answered in another question, e.g. Converting RGB to grayscale/intensity)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

被翻牌 2024-07-26 07:10:42

快速但肮脏的方法是重复 RGB 每个分量的灰度强度。 因此,如果灰度为 120,它将转换为 RGB (120, 120, 120)。

这是快速且肮脏的,因为您获得的有效亮度取决于您所使用的设备的 R、G 和 B 子像素的实际亮度。

The quick and dirty approach is to repeat the grayscale intensity for each component of RGB. So, if you have grayscale 120, it translates to RGB (120, 120, 120).

This is quick and dirty because the effective luminance you get depends on the actual luminance of the R, G and B subpixels of the device that you're using.

千秋岁 2024-07-26 07:10:42

如果您的灰度值在 0..255 范围内,并且想要生成 0x00RRGGBB 形式的新值,那么执行此操作的快速方法是:

int rgb = grey * 0x00010101;

或您选择的语言中的等效值。

If you have the greyscale value in the range 0..255 and want to produce a new value in the form 0x00RRGGBB, then a quick way to do this is:

int rgb = grey * 0x00010101;

or equivalent in your chosen language.

遇到 2024-07-26 07:10:42

将灰度转换为 RGB 很简单。 只需使用 R = G = B = 灰度值即可。 基本思想是颜色(在显示器上以 RGB 形式查看)是一个加法系统。

http://en.wikipedia.org/wiki/Additive_color

因此,将红色添加到绿色会产生黄色。 在该混合物中添加等量的蓝色,就会得到中性颜色。 完全打开 [红、绿、蓝] = [255 255 255] 会产生白色。 [0,0,0] 产生监视器黑色。 当 R=G=B 全部相等时,中间值将产生给定灰度级的名义上中性颜色。

一个小问题是,根据您如何看待颜色,它可能不是完全中性的。 这取决于您的显示器(或打印机)的校准方式。 从这一点开始,我们可以深入探讨色彩科学的有趣深度。 我就停在这里。

Conversion of a grayscale to RGB is simple. Simply use R = G = B = gray value. The basic idea is that color (as viewed on a monitor in terms of RGB) is an additive system.

http://en.wikipedia.org/wiki/Additive_color

Thus adding red to green yields yellow. Add in some blue to that mix in equal amounts, and you get a neutral color. Full on [red, green, blue] = [255 255 255] yields white. [0,0,0] yields monitor black. Intermediate values, when R=G=B are all equal will yield nominally neutral colors of the given level of gray.

A minor problem is depending on how you view the color, it may not be perfectly neutral. This will depend on how your monitor (or printer) is calibrated. There are interesting depths of color science we could go into from this point. I'll stop here.

李不 2024-07-26 07:10:42

灰度意味着所有值都具有相同的强度。 将所有通道(RGB)设置为等于灰度值,您将获得 RGB 黑白图像。

Grey-scale means that all values have the same intensity. Set all channels (in RGB) equal to the the grey value and you will have the an RGB black and white image.

几味少女 2024-07-26 07:10:42

将每个像素的 R、G 和 B 设置为相同的值(灰度值)难道不会获得正确的灰度吗?

Woudln't setting R,G,and B to the same value (the greyscale value) for each pixel get you a correct shade of gray?

情深已缘浅 2024-07-26 07:10:42

您还可以看看我的解决方案 更快将 RGB8 图像转换为 RGB32 图像的汇编优化方法。 灰色通道在所有其他通道中简单重复。

目的是找到使用 x86/SSE 进行转换的快速可能解决方案。

You may also take a look at my solution Faster assembly optimized way to convert RGB8 image to RGB32 image. Gray channel is simply repeated in all other channels.

The purpose was to find the fasted possible solution for conversion using x86/SSE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文