两张图片分别是光点位置的实验结果与理论结果图,通过matlab编写计算两张图片中俩光点偏离的大小
我可以提供一个基本的思路来计算每个光点位置的偏移量,具体步骤如下:
下面给出一个简单的代码示例,供参考:
% 读取两张图片
img1 = imread('theoretical_image.jpg');
img2 = imread('experiment_image.jpg');
% 显示两张图片
figure;
subplot(1,2,1);
imshow(img1);
title('Theoretical Image');
subplot(1,2,2);
imshow(img2);
title('Experiment Image');
% 将图片转为灰度图像
gray1 = rgb2gray(img1);
gray2 = rgb2gray(img2);
% 预处理灰度图像
gray1 = medfilt2(gray1, [3 3]); % 中值滤波去噪
gray2 = medfilt2(gray2, [3 3]);
gray1 = imgaussfilt(gray1, 2); % 高斯滤波平滑
gray2 = imgaussfilt(gray2, 2);
% 特征提取
points1 = detectSURFFeatures(gray1);
points2 = detectSURFFeatures(gray2);
% 特征匹配
features1 = extractFeatures(gray1, points1);
features2 = extractFeatures(gray2, points2);
indexPairs = matchFeatures(features1, features2);
matchedPoints1 = points1(indexPairs(:,1));
matchedPoints2 = points2(indexPairs(:,2));
% 计算偏移量
offsets = matchedPoints2.Location - matchedPoints1.Location;
% 在图像上显示偏移量
figure;
imshow(img1);
hold on;
scatter(matchedPoints1.Location(:,1), matchedPoints1.Location(:,2), 'r');
quiver(matchedPoints1.Location(:,1), matchedPoints1.Location(:,2), offsets(:,1), offsets(:,2), 'g');
title('Offset of Each Point');