Thread Subject: Image Processing (phase correlation)

Subject: Image Processing (phase correlation)

From: Brad White

Date: 20 Feb, 2008 20:36:01

Message: 1 of 9

I am trying to perform the steps necessary to do a phase
correlation between two images in order to determine the
amount of shift between them. These steps according to an
article on wikipedia about phase correlation are:
or at http://en.wikipedia.org/wiki/Phase_correlation

1) apply a window function to images (hamming window) for
edge effects.
2)then do a 2d fast fourier transformation on one image and
the complex conjugate of a 2d fast fourier transformation
on the other.
3)then multiply them by each other and divide by the
absolute value of them multiplied by each other.
4) do the inverse fast fourier transformation of that
result and then determine the location of the peak.

I belive my program isn't working right because i can't
seem to get a hamming window to work properly because it
leaves me with multiplication errors with the matrices.
I've tried many variations with my code but i can't seem to
get anything to work out right.
And i know i should be getting a black image with a bright
circle corresponding to the shift but i'm not getting
anything close to that.

Any help will be greatly appreciated.

What I have so far is:

image1 = imread('c:\....etc);
image2 = imread('c:\....etc);
Image1 = double(image1)*hamming(length(image1));
Image2 = double(image1)*hamming(length(image2));

FFT1 = fft2(double(Image1));
FFT2 = conj(fft2(double(Image2)));
FFTR = FFT1*FFT2;
FFTRN = (FFTR/abs((FFT1*FFT2)));
result = ifft2(double(FFTRN));

Subject: Image Processing (phase correlation)

From: Dave Robinson

Date: 21 Feb, 2008 09:35:03

Message: 2 of 9

"Brad White" <brad.white@mathworks.com> wrote in message
<fpi2vh$g8q$1@fred.mathworks.com>...
> I am trying to perform the steps necessary to do a phase
> correlation between two images in order to determine the
> amount of shift between them. These steps according to an
> article on wikipedia about phase correlation are:
> or at http://en.wikipedia.org/wiki/Phase_correlation
>
> 1) apply a window function to images (hamming window) for
> edge effects.
> 2)then do a 2d fast fourier transformation on one image and
> the complex conjugate of a 2d fast fourier transformation
> on the other.
> 3)then multiply them by each other and divide by the
> absolute value of them multiplied by each other.
> 4) do the inverse fast fourier transformation of that
> result and then determine the location of the peak.
>
> I belive my program isn't working right because i can't
> seem to get a hamming window to work properly because it
> leaves me with multiplication errors with the matrices.
> I've tried many variations with my code but i can't seem to
> get anything to work out right.
> And i know i should be getting a black image with a bright
> circle corresponding to the shift but i'm not getting
> anything close to that.
>
> Any help will be greatly appreciated.
>
> What I have so far is:
>
> image1 = imread('c:\....etc);
> image2 = imread('c:\....etc);
> Image1 = double(image1)*hamming(length(image1));
> Image2 = double(image1)*hamming(length(image2));
>
> FFT1 = fft2(double(Image1));
> FFT2 = conj(fft2(double(Image2)));
> FFTR = FFT1*FFT2;
> FFTRN = (FFTR/abs((FFT1*FFT2)));
> result = ifft2(double(FFTRN));

Have you tried

FFTR = FFT1.*FFT2;

and

FFTRN = (FFTR/abs((FFT1.*FFT2)));

You appear to be doing a matrix multiplication rather than a
frequency by frequency multiplication.

Regards

Dave Robinson

Subject: Image Processing (phase correlation)

From: Brad

Date: 21 Feb, 2008 14:41:03

Message: 3 of 9

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in
message <fpjgk7$qje$1@fred.mathworks.com>...
> "Brad White" <brad.white@mathworks.com> wrote in message
> <fpi2vh$g8q$1@fred.mathworks.com>...
> > I am trying to perform the steps necessary to do a
phase
> > correlation between two images in order to determine
the
> > amount of shift between them. These steps according to
an
> > article on wikipedia about phase correlation are:
> > or at http://en.wikipedia.org/wiki/Phase_correlation
> >
> > 1) apply a window function to images (hamming window)
for
> > edge effects.
> > 2)then do a 2d fast fourier transformation on one image
and
> > the complex conjugate of a 2d fast fourier
transformation
> > on the other.
> > 3)then multiply them by each other and divide by the
> > absolute value of them multiplied by each other.
> > 4) do the inverse fast fourier transformation of that
> > result and then determine the location of the peak.
> >
> > I belive my program isn't working right because i can't
> > seem to get a hamming window to work properly because
it
> > leaves me with multiplication errors with the matrices.
> > I've tried many variations with my code but i can't
seem to
> > get anything to work out right.
> > And i know i should be getting a black image with a
bright
> > circle corresponding to the shift but i'm not getting
> > anything close to that.
> >
> > Any help will be greatly appreciated.
> >
> > What I have so far is:
> >
> > image1 = imread('c:\....etc);
> > image2 = imread('c:\....etc);
> > Image1 = double(image1)*hamming(length(image1));
> > Image2 = double(image1)*hamming(length(image2));
> >
> > FFT1 = fft2(double(Image1));
> > FFT2 = conj(fft2(double(Image2)));
> > FFTR = FFT1*FFT2;
> > FFTRN = (FFTR/abs((FFT1*FFT2)));
> > result = ifft2(double(FFTRN));
>
> Have you tried
>
> FFTR = FFT1.*FFT2;
>
> and
>
> FFTRN = (FFTR/abs((FFT1.*FFT2)));
>
> You appear to be doing a matrix multiplication rather
than a
> frequency by frequency multiplication.
>
> Regards
>
> Dave Robinson


Thanks Dave it worked out great...

Brad

Subject: Image Processing (phase correlation)

From: fido genial

Date: 19 Mar, 2008 02:28:02

Message: 4 of 9

"Brad " <brad.white@mathworks.com> wrote in message
<fpk2hv$65p$1@fred.mathworks.com>...
> "Dave Robinson" <dave.robinson@somewhere.biz> wrote in
> message <fpjgk7$qje$1@fred.mathworks.com>...
> > "Brad White" <brad.white@mathworks.com> wrote in message
> > <fpi2vh$g8q$1@fred.mathworks.com>...
> > > I am trying to perform the steps necessary to do a
> phase
> > > correlation between two images in order to determine
> the
> > > amount of shift between them. These steps according to
> an
> > > article on wikipedia about phase correlation are:
> > > or at http://en.wikipedia.org/wiki/Phase_correlation
> > >
> > > 1) apply a window function to images (hamming window)
> for
> > > edge effects.
> > > 2)then do a 2d fast fourier transformation on one image
> and
> > > the complex conjugate of a 2d fast fourier
> transformation
> > > on the other.
> > > 3)then multiply them by each other and divide by the
> > > absolute value of them multiplied by each other.
> > > 4) do the inverse fast fourier transformation of that
> > > result and then determine the location of the peak.
> > >
> > > I belive my program isn't working right because i can't
> > > seem to get a hamming window to work properly because
> it
> > > leaves me with multiplication errors with the matrices.
> > > I've tried many variations with my code but i can't
> seem to
> > > get anything to work out right.
> > > And i know i should be getting a black image with a
> bright
> > > circle corresponding to the shift but i'm not getting
> > > anything close to that.
> > >
> > > Any help will be greatly appreciated.
> > >
> > > What I have so far is:
> > >
> > > image1 = imread('c:\....etc);
> > > image2 = imread('c:\....etc);
> > > Image1 = double(image1)*hamming(length(image1));
> > > Image2 = double(image1)*hamming(length(image2));
> > >
> > > FFT1 = fft2(double(Image1));
> > > FFT2 = conj(fft2(double(Image2)));
> > > FFTR = FFT1*FFT2;
> > > FFTRN = (FFTR/abs((FFT1*FFT2)));
> > > result = ifft2(double(FFTRN));
> >
> > Have you tried
> >
> > FFTR = FFT1.*FFT2;
> >
> > and
> >
> > FFTRN = (FFTR/abs((FFT1.*FFT2)));
> >
> > You appear to be doing a matrix multiplication rather
> than a
> > frequency by frequency multiplication.
> >
> > Regards
> >
> > Dave Robinson
>
>
> Thanks Dave it worked out great...
>
> Brad
>

Hi Brad

Is this code working...
I could see only black image without any white dot for
images with motion.

Let know if any changes are required to the code.

thanks
fido

Subject: Image Processing (phase correlation)

From: poonam jadhav

Date: 11 Apr, 2008 09:10:07

Message: 5 of 9

"Brad White" <brad.white@mathworks.com> wrote in message
<fpi2vh$g8q$1@fred.mathworks.com>...
> I am trying to perform the steps necessary to do a phase
> correlation between two images in order to determine the
> amount of shift between them. These steps according to an
> article on wikipedia about phase correlation are:
> or at http://en.wikipedia.org/wiki/Phase_correlation
>
> 1) apply a window function to images (hamming window) for
> edge effects.
> 2)then do a 2d fast fourier transformation on one image and
> the complex conjugate of a 2d fast fourier transformation
> on the other.
> 3)then multiply them by each other and divide by the
> absolute value of them multiplied by each other.
> 4) do the inverse fast fourier transformation of that
> result and then determine the location of the peak.
>
> I belive my program isn't working right because i can't
> seem to get a hamming window to work properly because it
> leaves me with multiplication errors with the matrices.
> I've tried many variations with my code but i can't seem to
> get anything to work out right.
> And i know i should be getting a black image with a bright
> circle corresponding to the shift but i'm not getting
> anything close to that.
>
> Any help will be greatly appreciated.
>
> What I have so far is:
>
> image1 = imread('c:\....etc);
> image2 = imread('c:\....etc);
> Image1 = double(image1)*hamming(length(image1));
> Image2 = double(image1)*hamming(length(image2));
>
> FFT1 = fft2(double(Image1));
> FFT2 = conj(fft2(double(Image2)));
> FFTR = FFT1*FFT2;
> FFTRN = (FFTR/abs((FFT1*FFT2)));
> result = ifft2(double(FFTRN));

Subject: Image Processing (phase correlation)

From: poonam jadhav

Date: 11 Apr, 2008 09:13:08

Message: 6 of 9

Hi;
i am using the same code for finding out the shift between
the two images. for that i have to plot the ifft,to find the
location of peak.
i.e.To plot "result" in the code you have given ,but i am
not getting it,pls help me regarding this.





"Brad White" <brad.white@mathworks.com> wrote in message
<fpi2vh$g8q$1@fred.mathworks.com>...
> I am trying to perform the steps necessary to do a phase
> correlation between two images in order to determine the
> amount of shift between them. These steps according to an
> article on wikipedia about phase correlation are:
> or at http://en.wikipedia.org/wiki/Phase_correlation
>
> 1) apply a window function to images (hamming window) for
> edge effects.
> 2)then do a 2d fast fourier transformation on one image and
> the complex conjugate of a 2d fast fourier transformation
> on the other.
> 3)then multiply them by each other and divide by the
> absolute value of them multiplied by each other.
> 4) do the inverse fast fourier transformation of that
> result and then determine the location of the peak.
>
> I belive my program isn't working right because i can't
> seem to get a hamming window to work properly because it
> leaves me with multiplication errors with the matrices.
> I've tried many variations with my code but i can't seem to
> get anything to work out right.
> And i know i should be getting a black image with a bright
> circle corresponding to the shift but i'm not getting
> anything close to that.
>
> Any help will be greatly appreciated.
>
> What I have so far is:
>
> image1 = imread('c:\....etc);
> image2 = imread('c:\....etc);
> Image1 = double(image1)*hamming(length(image1));
> Image2 = double(image1)*hamming(length(image2));
>
> FFT1 = fft2(double(Image1));
> FFT2 = conj(fft2(double(Image2)));
> FFTR = FFT1*FFT2;
> FFTRN = (FFTR/abs((FFT1*FFT2)));
> result = ifft2(double(FFTRN));

Subject: Image Processing (phase correlation)

From: khoo

Date: 7 May, 2009 16:04:01

Message: 7 of 9

bro, can update how your code?? i use your code also can't get the peak value and got black image without any white dot..

Subject: Image Processing (phase correlation)

From: bryan cahiles

Date: 12 Dec, 2010 05:39:05

Message: 8 of 9

"khoo" <jim_khoo@hotmail.com> wrote in message <gtv0ph$69s$1@fred.mathworks.com>...
> bro, can update how your code?? i use your code also can't get the peak value and got black image without any white dot..

please update the code

image1 = imread('a.jpg');
image2 = imread('aa.jpg');
Image1 = double(image1)*hamming(length(image1));
Image2 = double(image1)*hamming(length(image2));

FFT1 = fft2(double(Image1));
FFT2 = conj(fft2(double(Image2)));
FFTR = FFT1.*FFT2;
FFTRN = (FFTR/abs((FFT1.*FFT2)));
result = ifft2(double(FFTRN));


i have an error it says :

??? Error using ==> mtimes
Input arguments must be 2-D.

Subject: Image Processing (phase correlation)

From: Mohammad

Date: 13 Aug, 2011 00:47:29

Message: 9 of 9

HERE IS A MAJOR TYPO!!!

FFTRN = (FFTR/abs((FFT1*FFT2)));

SHOULD BE ->

FFTRN = (FFTR./abs((FFT1*FFT2)));
 
(notice how FFTR has a period after it...)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
phase correlation Said Pertuz 24 Nov, 2009 10:22:23
phase correlation poonam jadhav 11 Apr, 2008 05:15:11
hamming window Brad 20 Feb, 2008 15:40:00
fft Brad 20 Feb, 2008 15:40:00
image phase cor... Brad 20 Feb, 2008 15:40:00
rssFeed for this Thread

Contact us at files@mathworks.com