首先使用matlab进行选点

clear all
clc

% 读入可见光图像
EO_img=imread('NightNeedCal\026847.png');
% 读入红外图像
IR_img=imread('NightNeedCal\IR_026847.png');

% %展示读入的红外图像
% subplot(1,3,1),imshow(EO_img);
% %展示读入的红外图像
% subplot(1,3,2),imshow(IR_img);

% 选择匹配点对
[mp,fp] = cpselect(IR_img,EO_img,'Wait',true);

fixedPoints = fp
movingPoints = mp
% 将点保存
save('fp.mat', 'fixedPoints');
save('mp.mat', 'fixedPoints');

% % 如果需要的话,可以导入已经进行选择过的点
% fixedPoints = load('123\fp_000005.mat').fp;
% movingPoints = load('123\mp_000005.mat').mp;
tform = fitgeotrans(movingPoints,fixedPoints,'projective');
% writematrix(tform.T, 'tform.T.csv');
% 变换未配准的图像
Rfixed = imref2d(size(EO_img));
registered = imwarp(IR_img,tform,'OutputView',Rfixed);

imwrite(uint8(registered), "IR_OUT.png");
imshowpair(EO_img,registered,'blend')

% subplot(1,3,3),imshow(registered);

然后到python中使用透视变换

def get_H(moving_points_path, fixed_points_path):
    moving_points = scio.loadmat(moving_points_path)['mp']
    fixed_points = scio.loadmat(fixed_points_path)['fp']
    M, mask = cv2.findHomography(moving_points, fixed_points, cv2.RANSAC)
    return M
# 获得变换矩阵
M = get_H('./Scene' + str(Scene) + '/calibration/mp_000005.mat', './Scene' + str(Scene) + '/calibration/fp_000005.mat')

# 进行透视变换
w_l, h_l = 2048,1080
img1Reg = cv2.warpPerspective(IR_image_numpy, M, (h_l,w_l))
# 保存图片
cv2.imwrite('Scene1/DataSet/infrarded/' + 'IR_' + EO_img_Name, img1Reg)

检查图像配准结果

import cv2
import numpy as np

# 读取可见光图像和红外图像
visible_image = cv2.imread('./FusionOutput/' + '026847.png')

infrared_image = cv2.imread('./FusionOutput/' + 'IR_026847.png', cv2.IMREAD_GRAYSCALE)

heatmap = cv2.applyColorMap(infrared_image, cv2.COLORMAP_JET)

# 调整热力图的透明度
alpha = 0.5  # 设置透明度
overlay = heatmap * alpha + visible_image * (1 - alpha)

# 将 overlay 图像与 visible_image 图像合并
output_image = cv2.addWeighted(heatmap, alpha, visible_image, 1 - alpha, 0)

# 显示输出图像
cv2.imwrite('output_image.png', output_image)