且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

颜色检测算法 - 我应该怎么办呢?

更新时间:2023-01-17 17:18:29

两个想法浮现在脑海中:

Two thoughts come to mind:

廉价版:图像转换到HSV空间,并为每个像素计算 COS(H - target_hue)或合理的近似(蓝色, target_hue 将是240度),通过饱和相乘,并平均该数量在所有图像中的像素。高值是***的。需要注意的是颜色更接近黄色,而不是蓝色的有负青,而黑,白,灰纯有同样的零青。需要注意的是你真正想要的单纯疱疹病毒,不HSL,在这种情况下,因为在HSL的S没有很好地映射到感性的饱和度。例如,颜色#f8f8ff(RGB 248,248,255)具有100%的在HSL饱和(即一纯蓝色),但看起来近白色。相同颜色的HSV具有一S的只有3%,这是合理的坐标

Cheap version: convert images to HSV color space, and for each pixel compute cos(H - target_hue) or a reasonable approximation (for blue, target_hue would be 240 degrees), multiply by saturation, and average that quantity over all of the pixels in the image. High values are best. Note that colors that are closer to yellow than to blue have "negative blueness", and that black, white, and pure gray have equally "zero blueness". Note that you really want HSV, not HSL, in this situation, because the "S" in HSL doesn't map well to perceptual saturation. For example, the color #f8f8ff (RGB 248, 248, 255) has a saturation of 100% in HSL (i.e. a pure blue), but it looks nearly white. The same color in HSV has an "S" coordinate of only 3%, which is reasonable.

减廉价版:图像转换成CIELAB色彩空间,抛却L,并计算距离在每个像素的每个像素和目标颜色,然后平均值或有效值的A * B *空间。低值是***的。

Less cheap version: convert images to CIELAB color space, discard L, and compute the distance in a*b* space between each pixel and the target color, then average or RMS over each pixel. Low values are best.