我具有相同对象的热图图像和普通图像。与热图图像相比,正常图像会稍微移位。
现在,我想覆盖两个图像,但是为了这样做,我的最初方法是根据在线博客上的各种建议进行某种仿射变换。为此,假设我有两个不同的颜色图,则要进行边缘检测。所以现在我的图像如下:
但是,我不知道如何从这里开始。我应该如何进行?
这是一个具有挑战性的匹配问题,因为热图像太模糊了。
匹配边缘似乎是一个好主意,但我无法使其正常工作。
我想到使用某种轮廓匹配,例如following OpenCV示例。
似乎太困难了,所以我尝试使用内置的MATLAB函数imregcorr查找解决方案。仅当在每个轴上将图像调整大小为0.25时才找到该转换有效(因此结果不是“像素精确的”)。
该解决方案使用以下阶段:
imregcorr
查找几何变换估计,并对热图像进行变换(类似于imregcorr
文档中的示例)。 这里是MATLAB代码:
% Read images and convert to Grayscale
I1 = rgb2gray(imread('IR.png'));
I2 = rgb2gray(imread('vis.png'));
% Crop the relevant part
I1 = I1(27:320, 67:400);
I2 = I2(27:320, 67:400);
% Resize images by a factor of 0.25 (original IR image is too blurry)
I1 = imresize(I1, 0.25);
I2 = imresize(I2, 0.25);
% Normalize images - subtract mean and divide by STD
I1 = (double(I1) - mean2(I1)) / std2(I1) + 0.5;
I2 = (double(I2) - mean2(I2)) / std2(I2) + 0.5;
% Estimate the transformation needed to align the images using imregcorr.
tformEstimate = imregcorr(I1, I2, 'rigid');
% Apply estimated geometric transform to the I1 image
R2 = imref2d(size(I2));
J1 = imwarp(I1, tformEstimate, 'OutputView', R2);
% View I2 (VIS image) and warp I1 (warped IR image) side by side.
figure;imshowpair(I2, J1, 'montage')
注意:解决方案不是很可靠-我不得不尝试不同的参数,直到获得看起来像是正确转换的结果。
更新:
我在MATLAB File Exchange中找到了一个解决方案:Efficient subpixel image registration by cross-correlation
看起来好像正在工作(我不知道它是否健壮)。