How to match multiple images to one reference image using cross correlation?

19 views (last 30 days)
I have an image sequence containing 180 sequential images. I would like to match the images, one by one, to the first frame i.e. the first image of the data set is the reference image, the second one becomes the template which I would match to the reference successfully and then match the third to the previously obtained matched images, so on and so forth. I'm trying to do this using cross correlation but I can't seem to understand how to. Any help would be appreciated.

Answers (2)

Vidya Viswanathan
Vidya Viswanathan on 31 Mar 2016
Hi,
My understanding is that you would like to find matching features between two images and then apply some geometric transformation on the two images based on the matching features to perform image registration. There are a couple of functions available with Image Processing Toolbox that would help you. The following documentation page talks about Image Registration:
You would have to first detect the features using one of the feature extraction techniques listed and then perform feature matching to determine the corresponding features. Once the matched features are extracted, you could estimate and apply some geometric transformation to match the images. I hope this answers your question.
Regards,
Vidya

Image Analyst
Image Analyst on 31 Mar 2016
See my attached demo on normxcorr2.
You might also look into imregister().
  4 Comments
Chica_chic
Chica_chic on 16 Apr 2016
[row1,col1] = find(im); % im is the preprocessed image I pass into my function x1 = min(col1); y1 = min(row1); x2 = max(col1)-x1; y2 = max(row1)-y1; template = imcrop(im, [x1 y1 x2 y2]); %this part of the code finds a rectangular box, encasing the region which begins at the first occurrence of 1, in both x and y direction in the preprocessed (binary) image
%% calculate padding bx = size(background,2); by = size(background,1); tx = size(template,2); ty = size(template,1);
%% fft %Compute the cross power spectrum using phase correlation Ga = fft2(background); Gb = fft2(template, by, bx); %to produce a result of dimensions of background c = real(ifft2((Ga.*conj(Gb))./abs(Ga.*conj(Gb)))); %.* signifies Hadamard product (array multiplication)
%% find peak correlation, and hence point of registeration [max_c, imax] = max(abs(c(:))); %find point of registration [row,col] = ind2sub(size(c), imax); display best match hFig = figure; hAx = axes;
% position the rectangular template size on background image position = [row(1), col(1), tx, ty]; imshow(background, 'Parent', hAx); abc = imrect(hAx, position);
Image Analyst
Image Analyst on 16 Apr 2016
Please give us running code, not this:
Undefined function or variable 'im'.
Error in test3 (line 1)
[row1,col1] = find(im); % im is the preprocessed image I pass into my function
If you can demo your problem with a standard demo image like cameraman.tif, then please do so. If I did that, I get this:
Undefined function or variable 'background'.
Error in test3 (line 10)
bx = size(background,2);
Two strikes and you're out. I gave up after this.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!