假设有两幅图像imageA和imageB,那么它们的联合灰度直方图定义如下:
首先,要求两图像的大小是相同的;
其次,统计对应点上(iA, iB)灰度组合(I(iA), I(iB)出现的频率。
Matlab代码如下:
clear all; close all; clc;
image = imread('hedgebw.pgm');
imageA = image;
imageB = image;
[row, col] = size(image);
grayscale = 256;
jointHistogram = zeros(grayscale, grayscale);
for y = 1:row
for x = 1:col
jointHistogram(imageB(y, x) + 1, imageA(y, x) + 1) = ...
jointHistogram(imageB(y, x) + 1, imageA(y, x) + 1) + 1;
end
end
figure, imshow(mat2gray(jointHistogram)); title('联合概率分布');
对两幅完全相同的图像,它们的联合直方图类似于下图: