Вот что я хотел бы сделать:Как я могу обнаружить отличия от двух изображений и показать различия?
У меня есть два похожих изображения. Изображения могут быть разными по положению. Итак, я использовал детектор функции прибоя. И сопоставил эти функции с двумя изображениями и полученной матрицей преобразования. И я исказил первое изображение с этой матрицей преобразования. И в результате есть незначительный сдвиг от второго изображения. Поэтому я не могу использовать метод вычитания для поиска различий. Как я могу обнаружить различия и показать их, рисуя круг вокруг различий?
Я сейчас работаю с использованием matlab и python.
Вот мой код в MATLAB.
%% Step 1: Read Images
% Read the reference image containing the object of interest.
oimg1 = imread('test3_im1.jpg');
img1 = imresize(rgb2gray(oimg1),0.2);
figure;
imshow(img1);
title('First Image');
%%
% Read the target image containing a cluttered scene.
oimg2 = imread('test3_im2.jpg');
img2 = imresize(rgb2gray(oimg2),0.2);
figure;
imshow(img2);
title('Second Image');
%% Step 2: Detect Feature Points
% Detect feature points in both images.
points1 = detectSURFFeatures(img1);
points2 = detectSURFFeatures(img2);
%%
% Visualize the strongest feature points found in the reference image.
figure;
imshow(img1);
title('500 Strongest Feature Points from Box Image');
hold on;
plot(selectStrongest(points1, 500));
%%
% Visualize the strongest feature points found in the target image.
figure;
imshow(img2);
title('500 Strongest Feature Points from Scene Image');
hold on;
plot(selectStrongest(points2, 500));
%% Step 3: Extract Feature Descriptors
% Extract feature descriptors at the interest points in both images.
[features1, points1] = extractFeatures(img1, points1);
[features2, points2] = extractFeatures(img2, points2);
%% Step 4: Find Putative Point Matches
% Match the features using their descriptors.
pairs = matchFeatures(features1, features2);
%%
% Display putatively matched features.
matchedPoints1 = points1(pairs(:, 1), :);
matchedPoints2 = points2(pairs(:, 2), :);
figure;
showMatchedFeatures(img1, img2, matchedPoints1, matchedPoints2, 'montage');
title('Putatively Matched Points (Including Outliers)');
%% Step 5: Locate the Object in the Scene Using Putative Matches
% |estimateGeometricTransform| calculates the transformation relating the
% matched points, while eliminating outliers. This transformation allows us
% to localize the object in the scene.
[tform, inlierPoints1, inlierPoints2] = ...
estimateGeometricTransform(matchedPoints1, matchedPoints2, 'affine');
% tform_m = cp2tform(inlierPoints1,inlierPoints2,'piecewise linear');
% TFORM = cp2tform(movingPoints,fixedPoints,'piecewise linear')
%%
% Display the matching point pairs with the outliers removed
showMatchedFeatures(img1, img2, inlierPoints1, inlierPoints2, 'montage');
title('Matched Points (Inliers Only)');
%% detect difference
imgw = imwarp(oimg1, tform);
gim1 = rgb2gray(imgw);
gim2 = rgb2gray(oimg2);
sub = abs(gim1 - gim2);
imshow(sub);
Вам нужно указать код, чтобы показать, что вы сделали –
Можем ли мы увидеть исходные и разностные изображения? Могут быть разные причины. –
Невозможно сначала зарегистрировать изображения - используя Matlab. для регистрации вам нужно выбрать некоторые ключевые точки с совпадающим соответствием на двух изображениях. Тогда я считаю, что вы можете использовать алгоритм RANSAC в Matlab для получения матрицы преобразования, которая поможет вам восстановить исходное изображение. Затем следуйте рекомендациям JCKaz. – roni