Cropped Image vs Original Image

4 Ansichten (letzte 30 Tage)
Julie Fajgenbaum
Julie Fajgenbaum am 7 Nov. 2018
Beantwortet: Nick am 7 Nov. 2018
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:

Antworten (1)

Nick
Nick am 7 Nov. 2018
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