比较多个图像直方图与处理

Compare multiple Image Histograms with Processing

picture histogram

我对处理语言还很陌生。我正在尝试创建一个图像比较工具。

我们的想法是获取一张图片的直方图(见下面的截图,尺寸为 600x400),然后将其与其他 10 张类似图片的直方图(尺寸均为 600x400)进行比较。直方图显示了灰度级的频率分布,左侧显示纯黑色值的数量,右侧显示纯白色值的数量。

最后我应该得到一张 "winning" 图片(具有最相似直方图的图片)。

下面可以看到图像直方图的代码,类似处理教程的例子。

我的想法是为其他 10 张图片创建一个 PImage [] 以创建直方图,然后创建一个 if 语句,但我不确定如何编写代码。

有人知道如何进行或去哪里找吗?我找不到类似的 post.

提前致谢,如果问题很基础,我们深表歉意!

  size(600, 400);

    // Load an image from the data directory
    // Load a different image by modifying the comments

PImage img = loadImage("image4.jpg");
    image(img, 0, 0);
    int[] hist = new int[256];

    // Calculate the histogram

for (int i = 0; i < img.width; i++) {
      for (int j = 0; j < img.height; j++) {
        int bright = int(brightness(get(i, j)));
        hist[bright]++; 
      }
 }

    // Find the largest value in the histogram
    int histMax = max(hist);

    stroke(255);
    // Draw half of the histogram (skip every second value)

for (int i = 0; i < img.width; i += 2) {
      // Map i (from 0..img.width) to a location in the histogram (0..255)

int which = int(map(i, 0, img.width, 0, 255));
      // Convert the histogram value to a location between 
      // the bottom and the top of the picture

int y = int(map(hist[which], 0, histMax, img.height, 0));
      line(i, img.height, i, y);
    }

不确定您的问题是在处理中的实现还是您不知道如何比较直方图。我认为这是比较,因为其余部分非常简单。计算每个候选人的相似度并选出获胜者。

在网上搜索直方图比较,您会发现: http://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

OpenCV 实现了四种直方图相似性度量。

Correlation

where and N is the number of histogram bins

Chi-Square

Intersection

Bhattacharyya-Distance

您可以使用这些措施,但我相信您也会找到其他方法。