确定颜色“图像中单一颜色的含量”

发布于 2024-12-12 04:05:36 字数 199 浏览 0 评论 0原文

我试图计算整个图像上一种颜色的平均值,以确定颜色、饱和度或强度或描述视频帧之间这种变化的任何其他值。 然而,我只想得到一个可以描述整个框架的值(以及其中的单个选定颜色)。计算帧中颜色的简单平均值可以使视频帧之间的差异非常小,在 0..255 空间上只有 2-3 个差异。

除了直方图之外,还有其他方法可以确定图像的颜色吗?据我了解,直方图将为我提供多个描述单帧的值。

I’m trying to calculate an average value of one color over the whole image in order to determine how color, saturation or intencity or eny other value describing this changes between frmaes of the video.
However i would like to get just one value that will describe whole frame (and sigle, chosen color in it). Calculating simple average value of color in frame gives me very small differences between video frames, just 2-3 on a 0..255 space.

Is there any other method to determine color of the image other than histogram which as i understand will give me more than one value describing single frame.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

翻了热茶 2024-12-19 04:05:36

您使用哪个库进行图像处理?如果是 OpenCV(或 Matlab),那么这里的步骤将非常简单。否则你需要环顾四周并进行一些实验。

  1. 使用 RGB(或灰色)上的均值平移滤波器对图像中的颜色进行聚类 - 几乎相似的颜色会聚类在一起。这减少了要处理的颜色数量。

  2. 更改为灰度并使用图像中存在的像素值的区间 [0...255] 计算频率直方图

  3. 最高频率 - 中值 - 将对应于图像中存在的 bin(颜色)最多。每个垃圾箱的频率将为您提供编号。帧中存在的颜色的像素数。

  4. 将中值作为单一颜色来描述您的框架 - 框架中出现最多的颜色。

    这里的关键点是上述步骤对于实时视频是否足够快。我猜你必须尝试找出答案。

Which library are you using for image processing? If it's OpenCV (or Matlab) then the steps here will be quite easy. Otherwise you'd need to look around and experiment a bit.

  1. Use a Mean Shift filter on RGB (or gray, whichever) to cluster the colors in the image - nearly similar colors are clustered together. This lessens the number of colors to deal with.

  2. Change to gray-level and compute a frequency histogram with bins [0...255] of pixel values that are present in the image

  3. The highest frequency - the median - will correspond to the bin (color) that is present the most. The frequency of each bin will give you the no. of pixels of the color that is present in the frame.

  4. Take the median value as the single color to describe your frame - the color present in the largest amount in the frame.

    The key point here is if the above steps are fast enough for realtime video. You'd have to try to find out I guess.

酷炫老祖宗 2024-12-19 04:05:36

最坏的情况是,您可以循环图像中的所有像素并进行计数。不确定你正在使用什么编程方式,但我使用 Python 和 Numpy 类似的东西。其中 pb 是一个 gtk pixbuf,其中包含我的图像。

def pull_color_out(self, pb, *args):
    counter = 0
    dat = pb.get_pixels_array().copy()
    for y in range(0,pb.get_width()):
        for x in range(0,pb.get_height()):
            p = dat[x][y]
            #counts pure red pixels
            if p[1] = 255 and p[2] = 0 and p[3] = 0:
               counter += 1

    return counter

除此之外,我通常会使用直方图并从中获取我需要的数据。主要是,这不会是您最快的选择,尤其是对于视频而言,但如果您有时间或只有几帧,那么就放弃吧:P

Worst case scenario, you could loop over all the pixels in the image and do a count. Not sure what you are using programming wise but I use Python with Numpy something similar to this. Where pb is a gtk pixbuf with my image in it.

def pull_color_out(self, pb, *args):
    counter = 0
    dat = pb.get_pixels_array().copy()
    for y in range(0,pb.get_width()):
        for x in range(0,pb.get_height()):
            p = dat[x][y]
            #counts pure red pixels
            if p[1] = 255 and p[2] = 0 and p[3] = 0:
               counter += 1

    return counter

Other than that, I would normally use a histogram and get the data I need from that. Mainly, this will not be your fastest option, especially for a video, but if you have time or just a few frames then hack away :P

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