Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Phase correlation help needed

Subject: Phase correlation help needed

From: vivek

Date: 22 Dec, 2010 12:40:20

Message: 1 of 4

Hello guys,



I am trying to register 2 aerial images. I am planning to do this using phase correlation.

I have read the previous posts related to this but I haven't been able to understand the displacement vector.

Correct me if I am wrong.

The steps involved as I understand are:

1. Take fft of 2 images.
2. multiply 1st image by conjugate of 2nd(ref).divide the product by absolute value of numerator.
3. Take the Ifft of the result.
4. The maximum value of the above result would give me the displacement vector.

I have got a some questions
1. Should I do the phase correlation on the whole image or shall i divide both the images into subimages and then individually phase correlate them?
2. Depending on the maximum value how can I shift? i.e what can I infer from the maximum value. Please provide me the code or the algorithm to shift.

Please help me

Thanks

Subject: Phase correlation help needed

From: Sean de

Date: 22 Dec, 2010 16:10:21

Message: 2 of 4

"vivek" wrote in message <iesrjk$ssr$1@fred.mathworks.com>...
> Hello guys,
>
> I am trying to register 2 aerial images. I am planning to do this using phase correlation.
>
> I have read the previous posts related to this but I haven't been able to understand the displacement vector.
>
> Correct me if I am wrong.
>
> The steps involved as I understand are:
>
> 1. Take fft of 2 images.
> 2. multiply 1st image by conjugate of 2nd(ref).divide the product by absolute value of numerator.
> 3. Take the Ifft of the result.
> 4. The maximum value of the above result would give me the displacement vector.

Yes.

>
> I have got a some questions
> 1. Should I do the phase correlation on the whole image or shall i divide both the images into subimages and then individually phase correlate them?

That depends. Are your images distorted/contain internal deformations, or is it rigid body translation that you're trying to recover? For rigid body translation, use the whole image. To acquire a deformation field throughout the images, use sub-images.

> 2. Depending on the maximum value how can I shift? i.e what can I infer from the maximum value. Please provide me the code or the algorithm to shift.
>


Here's a small demo I wrote for someone on this topic back in March.
%%%%
function [row col] = PCdemo(I, I2)
%I,I2 are reference and target images
%[row col] are row, column shifts
%SCd 4/2010
%

    %Fourier transform both images
    fi = fft2(double(I));
    fr = fft2(double(I2));

    %Perform phase correlation (amplitude is normalized)
    fc = fi .* conj(fr);
    fcn = fc ./abs(fc);

    %Inverse fourier of peak correlation matrix and max location
    peak_correlation_matrix = abs(ifft2(fcn));
    [peak, idx] = max(peak_correlation_matrix(:));
    
    %Calculate actual translation
    [row, col] = ind2sub(size(peak_correlation_matrix),idx);
    if row < size(peak_correlation_matrix,1)/2
        row = -(row - 1);
    else
        row = size(peak_correlation_matrix,1) - (row - 1);
    end;
    if col < size(peak_correlation_matrix,2)/2
        col = -(col - 1);
    else
col = size(peak_correlation_matrix,2) - (col - 1);
    end
end


%%%
To verify that this works you can use my function imtranslate, available here:
http://www.mathworks.com/matlabcentral/fileexchange/27251-imtranslate
I = imread('cameraman.tif');
I2 = imtranslate(I,[3.6,-2.1]);
subplot(121)
imshow(I)
title('Original Image');
subplot(122);
imshow(I2)
title('Image shifted 3.6 down, 2.1 left');
[row_disp col_disp] = PCdemo(I,I2)


%Good Luck!
%-Sean

Subject: Phase correlation help needed

From: vivek

Date: 23 Dec, 2010 04:26:04

Message: 3 of 4

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iet7td$q3$1@fred.mathworks.com>...
> "vivek" wrote in message <iesrjk$ssr$1@fred.mathworks.com>...
> > Hello guys,
> >
> > I am trying to register 2 aerial images. I am planning to do this using phase correlation.
> >
> > I have read the previous posts related to this but I haven't been able to understand the displacement vector.
> >
> > Correct me if I am wrong.
> >
> > The steps involved as I understand are:
> >
> > 1. Take fft of 2 images.
> > 2. multiply 1st image by conjugate of 2nd(ref).divide the product by absolute value of numerator.
> > 3. Take the Ifft of the result.
> > 4. The maximum value of the above result would give me the displacement vector.
>
> Yes.
>
> >
> > I have got a some questions
> > 1. Should I do the phase correlation on the whole image or shall i divide both the images into subimages and then individually phase correlate them?
>
> That depends. Are your images distorted/contain internal deformations, or is it rigid body translation that you're trying to recover? For rigid body translation, use the whole image. To acquire a deformation field throughout the images, use sub-images.
>
> > 2. Depending on the maximum value how can I shift? i.e what can I infer from the maximum value. Please provide me the code or the algorithm to shift.
> >
>
>
> Here's a small demo I wrote for someone on this topic back in March.
> %%%%
> function [row col] = PCdemo(I, I2)
> %I,I2 are reference and target images
> %[row col] are row, column shifts
> %SCd 4/2010
> %
>
> %Fourier transform both images
> fi = fft2(double(I));
> fr = fft2(double(I2));
>
> %Perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./abs(fc);
>
> %Inverse fourier of peak correlation matrix and max location
> peak_correlation_matrix = abs(ifft2(fcn));
> [peak, idx] = max(peak_correlation_matrix(:));
>
> %Calculate actual translation
> [row, col] = ind2sub(size(peak_correlation_matrix),idx);
> if row < size(peak_correlation_matrix,1)/2
> row = -(row - 1);
> else
> row = size(peak_correlation_matrix,1) - (row - 1);
> end;
> if col < size(peak_correlation_matrix,2)/2
> col = -(col - 1);
> else
> col = size(peak_correlation_matrix,2) - (col - 1);
> end
> end
>
>
> %%%
> To verify that this works you can use my function imtranslate, available here:
> http://www.mathworks.com/matlabcentral/fileexchange/27251-imtranslate
> I = imread('cameraman.tif');
> I2 = imtranslate(I,[3.6,-2.1]);
> subplot(121)
> imshow(I)
> title('Original Image');
> subplot(122);
> imshow(I2)
> title('Image shifted 3.6 down, 2.1 left');
> [row_disp col_disp] = PCdemo(I,I2)
>
>
> %Good Luck!
> %-Sean

Thanks for replying Sean.

The program which you have written as I understand calculates the shift. Till this step I have understood.

After I calculate the translation how do I shift the slave image.

Can you please send me the link, so that I can have a better understanding of the concept.

The phase correlation values, is it with respect to the centre pixel.
My doubt is should i put the center pixel of the slave image window at the max correlation location or the first pixel?

Thanks

Subject: Phase correlation help needed

From: Sean de

Date: 23 Dec, 2010 13:04:21

Message: 4 of 4

"vivek" wrote in message <ieuj0s$gp7$1@fred.mathworks.com>...
> Thanks for replying Sean.
>
> The program which you have written as I understand calculates the shift. Till this step I have understood.
>
> After I calculate the translation how do I shift the slave image.
>
> Can you please send me the link, so that I can have a better understanding of the concept.
>
> The phase correlation values, is it with respect to the centre pixel.
> My doubt is should i put the center pixel of the slave image window at the max correlation location or the first pixel?
>
> Thanks

You're welcome!

To shift the image, use the imtranslate function and the negative shift returned from the phase correlation.

One other idea that might help you is to zero-pad (doc padarray) both image before doing the correlation, run the correlation, shift the second image with imtranslate, crop to remove the padding.

Good Luck!
-Sean

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us