如何确定颜色是否更接近白色或黑色? [英] How do I determine if a color is closer to white or black?

查看:1352
本文介绍了如何确定颜色是否更接近白色或黑色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在处理皮肤色调,并想确定一个人的肤色是否更接近白色或黑色。

I am dealing with skin tones and would like to determine if a person's skin tone is closer to white or black.

因此,考虑到颜色,如何确定它是更接近白色肤色还是黑色?

So given a color, how does one determine if it is closer to a white skin tone or a black one?

我尝试了一些noobish算法,有没有人知道我该怎么做?

I have tried some noobish algorithms, does anyone know how I can do this?

推荐答案

我会说,你可以先将颜色转换为灰度,然后检查它是否更接近黑色或白色。

I would say that you can first convert the color to gray scale and then check if it's nearer to black or white.

首先转换RGB颜色值计算亮度以下公式

First convert the RGB color value to compute luminance by the following formula

Y = 0.2126*R + 0.7152*G + 0.0722*B

然后检查值是否更接近0或255,并相应地选择黑色或白色

Then check if the value is nearer to 0 or to 255 and choose black or white accordingly

color c = Y < 128 ? black : white

请注意,如果颜色空间不是gamma压缩,在计算作为γ扩展的亮度之前添加一个步骤,计算Y,然后执行γ压缩以获得非线性亮度值,然后可以使用该非线性亮度值决定颜色是否更接近黑色或白色。

Mind that this works well if the color space is not gamma compressed, otherwise you will have to add a step before calculating the luminance which is a gamma expansion, compute Y, then perform a gamma compression to obtain a non-linear luminance value that you can then use to decide if color is nearer to black or white.

这篇关于如何确定颜色是否更接近白色或黑色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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