Phase correlation between images of different sizes
9 ビュー (過去 30 日間)
古いコメントを表示
I am trying to find the phase correlation between two images of different sizes with the following code, am I doing something wrong here? because the correlation is not very good for a few sets.
function [indx indy] = bph_correl(image1,image2,th_mat)
%image1 = imread('image1.jpg');
%image2 = imread('template4.jpg');
% convert to double
Image1 = double(image1(:,:,1));
Image2 = double(image2(:,:,1));
% thresholding to binarize
th_img1 = localthreshold(Image1,th_mat);
th_img2 = localthreshold(Image2,th_mat);
% figure;imshow(th_img1);
% figure;imshow(th_img2);
[x1 y1]= size(th_img1);
[x2 y2]= size(th_img2);
padx = x1 + x2 -1;
pady = y1 + y2 -1;
% pad zeros to the images to avoid wrap around errors
pimage1 = double(zeros(padx,pady));
pimage2 = double(zeros(padx,pady));
pimage1(1:x1,1:y1) = th_img1;
pimage2(1:x2,1:y2) = th_img2;
%fft of image1
FFT1 = fft2(pimage1); % 2d FFT
% conjugate of fft of image2
FFT2 = conj(fft2(pimage2));
% numerator
FFTR = FFT1.*FFT2;
% denominator
magFFTR = abs(FFTR) + 1;
% result with magnitude part removed
FFTRN = (FFTR./magFFTR);
% inverse fourier
result1 = ifft2(double(FFTRN));
% seperating only the region of interest
result = result1(1:x1,1:y1);
% finding the index of the peak
[arr ind] = max(result(1:x1,1:y1));
[val indy]= max(arr);
indx= ind(indy);
% result part from the original image
res_img = uint8(Image1(indx:indx+x2-1,indy:indy+y2-1));
imshow([res_img Image2]);
end
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!