检查像素(RGB 或 HSV)是否包含在色阶范围内,如何
我需要检查像素(RGB)是否包含在从非常浅的粉色到深紫色的色阶中。 使用 RGB 方案我可以进行这样的检查:
IF image [x, y] [R]> threshold and image [x, y] [G]> threshold image [x, y] [B]> threshold and \
image [x, y] [R] <threshold and image [x, y] [G] < threshold image [x, y] [B] <threshold THAN ...
?
如果没有,我还可以选择将像素置于 HSV 中。
谢谢!
I need to check if a pixel (RGB) is contained in the color scale ranging from very light pink to dark purple.
Using the RGB scheme can I do a check like this:
IF image [x, y] [R]> threshold and image [x, y] [G]> threshold image [x, y] [B]> threshold and \
image [x, y] [R] <threshold and image [x, y] [G] < threshold image [x, y] [B] <threshold THAN ...
?
If not, I also have available the option of having the pixel in HSV.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想要使用 HSV,因为它比 RGB 更直观地映射到人类感知。如果你让一个人将颜色标记为“在范围内”或“在范围外”,并将它们映射到 HSV 中,你将能够找到指示进入和退出的 H、S 和 V 值的界限。
然后,您可以使用简单的范围检查(如您概述的那样)来确定颜色是在内部还是在外部。如果您需要 Python 帮助进行颜色空间转换,标准库模块
colorsys
将为您完成。You probably want to work in HSV, because it maps much more intuitively to human perception than RGB. If you get a human to mark colors as "in range" or "out of range", and map them in HSV, you'll be able to find a bound on the H, S, and V values that indicates in and out.
Then you can use a simple range check like you've outlined about to determine if a color is in or out. If you need Python help with the color space conversions, the standard library module
colorsys
will do it for you.使用每通道截止值相当于在 RGB 颜色空间中指定一个轴对齐的矩形框。盒子是一种令人讨厌的形状 - 您可能必须包含一些您并不真正想要的区域(在角落),以避免排除您确实想要的区域(在脸部的中心)。
如果您选择两个锚点和一个截止距离,则它相当于任意对齐的 3D 椭球体 - 它有望更准确地匹配您想要的颜色。
类似的东西
Using per-channel cut-off values is equivalent to designating an axis-aligned rectangular box in RGB color space. A box is kind of a nasty shape - you will likely have to include some areas you don't really want (in the corners) to avoid excluding areas you do want (in the center of the faces).
If you instead choose two anchor points and a cut-off distance, it is the equivalent of an arbitrarily aligned 3d ellipsoid - which should hopefully more accurately match the colors you want.
Something like
如果您谈论的是整数 RGB 值,则可以将所有值放入
set
中,然后只需执行if color in set:
如果您的“颜色范围”是以复杂的方式定义,定义一组具体的颜色可能是唯一的方法。
If you're talking about integer RGB values, you can put all of the values into a
set
and then simply doif color in set:
If your 'color range' is defined in a complex way, defining a concrete set of colors might be the only way.