Cropped Image vs Original Image
조회 수: 4 (최근 30일)
이전 댓글 표시
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개)
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);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!