确定 ARGB 范围之间的像素颜色
好吧,我正在努力研究我的车牌检测算法,并且需要一些简单的帮助。
基本上我正在尝试执行以下操作,代码是不言自明的,我只是找不到我想要实现的示例。
提前感谢
if (img.GetPixel(bottomRightc.X, y) <= Color.FromArgb(255, 255, 255, 255)
&&
img.GetPixel(bottomRightc.X, y) >= Color.FromArgb(255, 166,166,166))
{
return false;
}
编辑:
感谢大家的回复,我没有太多考虑比较,并在创建此线程后看到了问题。我想我会进行亮度比较,因为我的图像已经灰度化并且具有高对比度。
Well I'm working hard on my vehicle license plate detection algorithm, and need a little help with something simple.
Basically I'm trying to do the following, the code is self explanatory, I just can't find an example of what I'm trying to implement.
Thanks in advance
if (img.GetPixel(bottomRightc.X, y) <= Color.FromArgb(255, 255, 255, 255)
&&
img.GetPixel(bottomRightc.X, y) >= Color.FromArgb(255, 166,166,166))
{
return false;
}
EDIT:
Thanks for the replies everyone, I didn't put much thought into the comparison, and saw the problem with it after creating this thread. I think I'll go with brightness comparison since my image has been grayscaled and has a high contrast.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否考虑过在其他色彩空间中工作?使用 HSV/HSB,您可以简单地执行诸如
假设值/亮度 0-255 的最小值-最大值之类的操作。假设您正在尝试完成亮度比较,这对我来说并不完全清楚。
编辑:
System.Drawing.Color中有相关方法,亮度在0.0和1.0之间。所以上面的内容会变成这样:
Have you considered working in another color space? With HSV/HSB you could simply do something like
Assuming min-max of Value/Brightness 0-255. And assuming you are trying to accomplish brightness comparison, which is not entirely clear to me.
Edit:
There are methods for this in System.Drawing.Color, and brightness is between 0.0 and 1.0. So the above would become ~something like this:
为了正确比较,您需要为每种颜色导出一个值。一个很好的候选者是光度,它很好 此处介绍。 (有关该主题的 wiki 文章 使用一组略有不同的系数进行计算。 )
测试亮度可以让您比较两种颜色的相对明度/暗度。这对于您的车牌检测算法来说非常方便,因为车牌是黑白的。
文章中计算颜色的光度或亮度的示例:
尝试比较各个 R、G 和 B 值很可能会给您带来麻烦。
For proper comparison you will need to derive to a single value for each color. A good candidate is luminosity which is nicely covered here. (The wiki article on the topic uses a slightly different set of coefficients for calculations.)
Testing luminosity will allow you to compare the relative lightness/darkness of two colors. This could be very handy for your license plate detection algorithm since the plate is black and white.
Article's example of calculating a color's luminosity, or brightness:
Trying to compare on the individual R, G and B values will most likely get you into trouble otherwise.
没有为 System.Drawing.Color 定义比较运算符,因此您必须实现自己的比较方法。我建议使用扩展方法,例如:
这样您就可以使用
或
Comparison operators are not defined for
System.Drawing.Color
, so you have to implement your own comparison methods. I suggest using an extension method, for example:so you can use
or
这是我比较颜色的解决方案:
我想您可以进行修改以满足您的特定需求!基本上它通过色调比较颜色,然后通过饱和度,最后通过亮度! (我用它来排序颜色。)
Here's my solution to compare colours:
I suppose that you can modify to fit your specific needs! Basically it compares the colour by hue, then by saturation and at last by brightness! (I use this for sorting colours.)