Cropped Image vs Original Image

3 ビュー (過去 30 日間)
Julie Fajgenbaum
Julie Fajgenbaum 2018 年 11 月 7 日
回答済み: Nick 2018 年 11 月 7 日
I have two images: The Original Image and the Cropped Image. I want to compare the two to determine the coordinates of the cropping on the original. (For example... starting at the top left of the Original Image, the crop is X number of pixels to the right and Y number of pixels down.) Thank you!
THIS IS THE ORIGINAL IMAGE FOLLOWED BY THE CROPPED IMAGE:
  1 件のコメント
Julie Fajgenbaum
Julie Fajgenbaum 2018 年 11 月 7 日
Yes, exactly!

サインインしてコメントする。

回答 (1 件)

Nick
Nick 2018 年 11 月 7 日
If the cropped image was not resized this can be solved by using a template matching approach with normxcorr2.
% convert the images to grayscale
template = rgb2gray(cropped);
A = rgb2gray(original);
C = normxcorr2(template,A);
% get the highest value returned by normxcorr2
[~, index] = max(C(:));
[row,column] = ind2sub(size(C),index); % return the linear index to (row, column)
% shows an image with the bottom right corner of the cropped image in the original
figure;
imshow(original);
hold on;
plot(column, row,'rx','MarkerSize',3);
% get the all indices of the cropped image
rowIndices = row-size(cropped,1)+1:row;
columnIndices = column-size(cropped,2)+1:column;
% get the gray cropped image in all 3 rgb channels than overwrite the cropped are to be gray and display
croppedGray = repmat(template,[1 1 3]);
mergedImage = original;
mergedImage(rowIndices,columnIndices,:) = croppedGray;
figure;
imshow(mergedImage);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by