我如何判断 RGB 颜色基本上是蓝色?在 c# 中

发布于 2024-11-16 00:45:21 字数 242 浏览 2 评论 0原文

我有一组天空的图像,有些有云,有些没有。

有些是晴朗的蓝天,有些是阴天,有些是阴暗的白色和灰色的云。

如何确定特定 RGB 值或多或少是蓝色?

任何蓝色阴影都是“蓝色”——浅蓝色、深蓝色、海军蓝、天蓝色——这些都是蓝色。

我想将图像中的颜色减少到 16 种。然后我想制作白色、银色、灰色、蓝色和“其他所有颜色”的直方图。

我如何从 RGB 值知道什么是蓝色或银色、白色或灰色,还是其他颜色?

I have a set of images of the sky, some with clouds, and some without.

Some are clear blue skies, some partly cloudy, some murky with white and grey clouds.

How can I determine that a particular RGB value is, more or less, blue?

Any shade of blue is 'blue' - light blue, dark blue, navy blue, sky blue - these are all blue.

I want to reduce the colors in the image down to 16. Then I want to make a histogram of White, Silver, Grey, Blue and 'everything else'.

How do I know from the RGB value what is a blue or a silver, a white or a grey, or something else?

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

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

发布评论

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

评论(3

不交电费瞎发啥光 2024-11-23 00:45:21

RGB 并不是处理这类事情的最佳色彩空间。 HSV(也称为 HSB) 等色彩空间为给定的颜色。

因此,要获得您想要的效果,您可以使用给定颜色的色相。如果您正在处理 System.Drawing.Color 结构,则可以使用 GetHue() 方法,返回以度为单位的色调值。给定如下所示的色相轮,您可以为您接受的蓝色值定义上限和下限(以度为单位)。

Hue Wheel

图像处理和色彩理论一般来说绝非微不足道的主题。我建议您找到满足您要求的最简单的方法。这对您来说可能足够了,也可能不够。如果没有,那么也许你可以帮我缩小问题范围。

另请注意,您仍然需要亮度和饱和度组件的一些阈值,以确保您实际上处理的不是黑色、白色或灰色。

RGB isn't the best color space to work in for this sort of thing. A color space such as HSV (also known as HSB) provides a more intuitive and descriptive model for a given color.

So, to get what you are after you can use the Hue of a given color. If you are dealing with a System.Drawing.Color structure you can use the GetHue() method which returns a hue value in degrees. Given a Hue wheel like the following you can define an upper and lower threshold (in degrees) for what Blue values you will accept.

Hue Wheel

Image processing and Color theory in general are far from trivial subjects. I would suggest that you find the simplest method that meets your requirements. This may be enough for you, or maybe not. If not then perhaps you can narrow the question down a bit for me.

Also realize that you will still need some threshold for the Brightness and Saturation components to ensure that you aren't actually dealing with black, white, or gray.

故人的歌 2024-11-23 00:45:21

如果红色和绿色值接近相同,并且蓝色值大于红色和绿色值,则颜色将在蓝色范围内。如果所有三个值大致相同,则您会得到某种版本的灰色,如果它们都接近最大值,则颜色将看起来是白色。不可能比这更精确了——您只需查看颜色选择器并找出哪个区域对您来说看起来“蓝色”。

If the red and green values are close to the same, and if the blue value is greater than the red and green values, the color is going to be in the blue range. If all three values are about the same, you've got some version of grey, and if they're all close to their maximum the color will look white. It's impossible to be much more precise than that -- you'll need to just look at a color picker and figure out which region looks "blue" to you.

念三年u 2024-11-23 00:45:21

也许可以构建一个表,其中包含您想要的 16 种颜色中每种颜色的 RGB 值,然后将每个像素的 RGB 值与表中的每个值进行比较。
要进行比较,请进行减法,例如 R1-R2 G1-G2 B1-B2,然后总结差异并将其转换为差异较小的颜色。

相关问题:比较c#中的RGB颜色

Maybe build a table with the RGB values for each of the 16 colors you want, then compare each pixel RGB value to each of the values in your table.
To compare make a substraction like R1-R2 G1-G2 B1-B2 then sum up the differences and convert it to the color that is less different.

Related question: Compare RGB colors in c#

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