Sub-pixel precision template matching using normalized cross-correlation (normxcorr2)

30 visualizaciones (últimos 30 días)
Hello!
I am using normxcorr2 function to compute the displacement and velocity of certain region between two images. The problem is that normxcorr2 function returns result as an integer value and it doesn't evaluate sub-pixel displacemeent.
The only solution that I found is using imresize function with bicubic interpolation. I increase the size of the image 5 times and obtain better accuracy.
My question is: Is using of imresize the only option to get sub-pixel precision template matching using nomxcorr2 or are there any better options?
Original image pair:
t
t + dt, dt > 0
Here is the image pair processing result without scaling and the corresponding cross-correlation surface:
This is the image pair processing result with scaling using imresize function (x5 scaling), the measured velocity is now closer to the real one:
firstImage = imresize(firstImage, 5, 'bicubic');
secondImage = imresize(secondImage, 5, 'bicubic');
The main part of my code calculating normalized cross-correlation:
function [offsetX, offsetY] = calculateCrossCorrelation(refImage, targetImage, displayImages)
if displayImages
figure(1);
imshowpair(refImage, targetImage, 'montage');
end
c = normxcorr2(refImage, targetImage);
if displayImages
figure();
surf(c);
shading flat;
end
% Find the peak in cross-correlation
[ypeak,xpeak] = find(c==max(c(:)));
% Account for the padding that normxcorr2 adds
yoffSet = ypeak-size(refImage,1);
xoffSet = xpeak-size(refImage,2);
if displayImages
figure(3);
imshow(targetImage);
drawrectangle(gca,'Position',[xoffSet, yoffSet,...
size(refImage,2), size(refImage,1)], ...
'FaceAlpha',0);
end
offsetX = xoffSet;
offsetY = yoffSet;
end
  1 comentario
Edoardo
Edoardo el 10 de En. de 2024
Hi, you can use Efficient subpixel image registration by cross-correlation which does the upscaling in a much faster way and allows for a greater upscaling factor for a given memory usage.
Hope this helps and I'm not too late answering
%usfac is the upscale factor, 5 in your case
output = dftregistration(fft2(refImage),fft2(targetImage),usfac);
offsetX = output(3);
offsetY = output(4);
% The images are registered to within 1/usfac of a pixel.
% output(1) is the normalized root-mean-squared error (NRMSE) [1] between refImage and targetImage.
% output(2) is the global phase difference between the two images (should be zero if images are real-valued and non-negative).
% output(3) and output(4) are the row and column shifts between refImage and targetImage respectively.

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by