Normalized 2-D cross-correlation
clear
close all;
clc;
img =imread('C:\Users\US\Desktop\Image Processing Practice\Images\4.jpg');
img = rgb2gray(imresize(img,0.25));
figure('units', 'normalized', 'outerposition', [0 0 1 1]),
subplot(221),imshow(img),title('Original Resize Image');
[row,col]=size(img);
cropped_img = imcrop(img, [row/2 100 200 col/2]);
subplot(222),imshow(cropped_img),title('Sub-Region');
%Perform cross-correlation
c = normxcorr2(cropped_img,img);
% Find the peak in cross-correlation
[ypeak, xpeak]= find(c==max(c(:)));
% Account for the padding that normxcorr2 adds
yoffset = ypeak-size(cropped_img,1);
xoffset = xpeak-size(cropped_img,2);
%% Display the matched area
subplot(223), imshow(img),title('Normalized Cross-Correlation Output');
imrect(gca, [xoffset+1, yoffset+1,size(cropped_img,2),size(cropped_img,1)]);
0 Comments