图像直方图比较

Image Histogram Comparison

我试图在两个 RGB 图像之间进行直方图图像比较,其中包括同一个人的头部和非头部,以查看它们之间的相关性。我这样做的原因是因为在使用 HOG 执行扫描以检查扫描 window 是否是头部之后,我现在试图在随后的帧中跟踪同一个头部并且我还想删除一些明显的错误正面。

我目前尝试了 RGB 和 HSV 直方图比较,并使用欧氏距离来检查直方图之间的差异。以下是我写的代码:

%RGB histogram comparison

 %clear all;
img1 = imread('testImages/samehead_1.png');
img2 = imread('testImages/samehead_2.png');

img1 = rgb2hsv(img1);
img2 = rgb2hsv(img2);

%% calculate number of bins = root(pixels);
[rows, cols] = size(img1);
no_of_pixels = rows * cols;
%no_of_bins = floor(sqrt(no_of_pixels));
no_of_bins = 256;

%% obtain Histogram for each colour
% -----1st Image---------
rHist1 = imhist(img1(:,:,1), no_of_bins);
gHist1 = imhist(img1(:,:,2), no_of_bins);
bHist1 = imhist(img1(:,:,3), no_of_bins);

hFig = figure;
hold on;
h(1) = stem(1:256, rHist1);
h(2) = stem(1:256 + 1/3, gHist1);
h(3) = stem(1:256 + 2/3, bHist1);

set(h, 'marker', 'none')
set(h(1), 'color', [1 0 0])
set(h(2), 'color', [0 1 0])
set(h(3), 'color', [0 0 1])

hold off;

% -----2nd Image---------
rHist2 = imhist(img2(:,:,1), no_of_bins);
gHist2 = imhist(img2(:,:,2), no_of_bins);
bHist2 = imhist(img2(:,:,3), no_of_bins);

hFig = figure;
hold on;
h(1) = stem(1:256, rHist2);
h(2) = stem(1:256 + 1/3, gHist2);
h(3) = stem(1:256 + 2/3, bHist2);

set(h, 'marker', 'none')
set(h(1), 'color', [1 0 0])
set(h(2), 'color', [0 1 0])
set(h(3), 'color', [0 0 1])

%% concatenate values of a histogram in 3D matrix
% -----1st Image---------
M1(:,1) = rHist1;
M1(:,2) = gHist1;
M1(:,3) = bHist1;

% -----2nd Image---------
M2(:,1) = rHist2;
M2(:,2) = gHist2;
M2(:,3) = bHist2;

%% normalise Histogram
% -----1st Image---------
M1 = M1./no_of_pixels;
% -----2nd Image---------
M2 = M2./no_of_pixels;

%% Calculate Euclidean distance between the two histograms
E_distance = sqrt(sum((M2-M1).^2));

E_distance 由一个包含 3 个距离的数组组成,这些距离指的是红色直方图差异、绿色和蓝色。

问题是:

有人可以向我解释一下我是否正确地执行此操作,或者对我应该做什么有任何指导吗?

PS:我从这篇论文(Affinity Measures 部分)得到了 LAB 直方图比较的想法:People Looking at each other

颜色直方图相似度可用作检测跟踪的良好线索,但不要指望它能消除人与人和人与非人之间所有可能的匹配。

根据您的代码,您可以做一件事来改进比较:目前,您正在使用每个通道的直方图。这不够具有辨别力,因为您不知道 R-G-B 组件何时同时出现(例如,您知道红色通道在 64-96 范围内有多少次以及蓝色通道在 32-64 范围内有多少次,但不知道这些发生的时间同时)。要纠正这个问题,您必须使用 3D 直方图,计算颜色的共现)。对于每个通道 8 个箱子的离散化,您的直方图将有 8^3=512 个箱子。

其他改进建议:

  1. 根据插值权重对相邻 bin 进行加权分配。这消除了 bin 量化引入的不连续性
  2. 检测层级拆分window到单元格(1个单元格,4个单元格,16个单元格等),每个单元格都有自己的直方图,其中不同级别和单元格的直方图连接在一起。这允许捕捉局部颜色细节,比如衬衫的颜色,或者更局部的,衬衫 pocket/sleeve.
  3. 使用地球移动距离 (EMD) 而不是欧几里得度量来比较直方图。这减少了颜色量化效果(直方图中的差异由颜色-space 距离而不是相等的权重加权),并允许检测范围内的细胞定位存在一些误差 window.
  4. 使用其他线索进行跟踪。您会惊讶于您的检测的 HoG 描述符之间的相似性在多大程度上有助于消除匹配歧义!