比较两个组件的颜色
我想比较具有填充颜色的组件是否相等 我执行以下算法,我对 RGB 进行平均,然后
double avg1 =(comp[0].Red+comp[0].Blue+comp[0].Green)/3;
double avg2 =(comp[1].Red+comp[1].Blue+comp[1].Green)/3;
将它们进行比较,
double ratio = avg1/avg2 ;
if(ratio > 0.8 && ratio < 1.2){} //then they are supposed to be equal
但这种方法在搜索后根本不准确,
我发现最好的方法是将图像转换为 HSL 空间并进行比较 但我不知道如何比较两种颜色?!! 这里
换句话说,将图像转换为 HSL 空间后我能做什么?!
请帮忙!
修改问题以获得更多澄清 我的意思是组件(点序列),所以在平均步骤中,实际上我重新访问所有点,计算每个像素的 RGB 平均值之和,然后对总点数进行平均
i want to compare to components with their filled colors if they are equal or not
i do the following algorithm , i do averaging for the rgb as following
double avg1 =(comp[0].Red+comp[0].Blue+comp[0].Green)/3;
double avg2 =(comp[1].Red+comp[1].Blue+comp[1].Green)/3;
then compare them as following
double ratio = avg1/avg2 ;
if(ratio > 0.8 && ratio < 1.2){} //then they are supposed to be equal
but this way isn't accurate at all
after searching i found that the best way is converting the image to HSL space and compare
but i can't get how i compare 2 colors ?!! here
in other words after converting the image into HSL space what can i do ?!
help please !!
modification to the question for more clarification
i mean with component (sequence of points) so in the averaging step actually i revisit all the points calculating the sum of the average of rgb for each pixel , then do averaging over the total number of the points
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
转换为 HSL 并使用 H(色调)的差异对颜色进行分组。
Convert to HSL and use the difference in H (hue) to group colors.
因此,如果您的问题是“将图像转换为 HSL 空间后我该怎么办?!”然后这里是:
cvCvtColor()
和CV_RGB2HLS
标志将您加载的 RGB 图像转换为 HSL(HSL 图像自然应该是 3 通道)cvSplit( hls, h, l, s, 0 )
将 HSL 图像分离为通道希望这有帮助。
So if your question is "after converting the image into HSL space what can i do ?!" then here goes:
cvCvtColor()
with theCV_RGB2HLS
flag (the HSL image should be 3-channel, naturally)cvSplit( hls, h, l, s, 0 )
to separate the HSL image into channelsHope this helps.