比较两个组件的颜色

发布于 2024-11-23 18:14:24 字数 792 浏览 3 评论 0原文

我想比较具有填充颜色的组件是否相等 我执行以下算法,我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-11-30 18:14:25

转换为 HSL 并使用 H(色调)的差异对颜色进行分组。

Convert to HSL and use the difference in H (hue) to group colors.

浮生未歇 2024-11-30 18:14:25

因此,如果您的问题是“将图像转换为 HSL 空间后我该怎么办?!”然后这里是:

  1. 使用 cvCvtColor()CV_RGB2HLS 标志将您加载的 RGB 图像转换为 HSL(HSL 图像自然应该是 3 通道)
  2. 使三个将 H、L、S 通道的单通道图像(大小相同)分离为
  3. cvSplit( hls, h, l, s, 0 ) 将 HSL 图像分离为通道
  4. 现在 h_image 将就像任何单通道灰度图像一样。因此,在提取组件后(通过对 RGB 图像进行阈值处理来执行此操作,有时色调通道图像看起来很奇怪:P),只需比较色调图像中与其坐标相对应的颜色即可。

希望这有帮助。

So if your question is "after converting the image into HSL space what can i do ?!" then here goes:

  1. convert the RGB image you've loaded to HSL using cvCvtColor() with the CV_RGB2HLS flag (the HSL image should be 3-channel, naturally)
  2. make three single-channel images (of same size) for the H, L, S channels to be separated into
  3. cvSplit( hls, h, l, s, 0 ) to separate the HSL image into channels
  4. Now the h_image will be just like any single-channel grayscale image. So after extracting components (do this from thresholding the RGB image, sometimes Hue channel image looks weird :P) simply compare the colors in the hue image that correspond to their co-ordinates.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文