DSPRelated.com
Forums

Zero padding FFTed cross correlation

Started by Frederick Mengin July 3, 2009
Hello,

I try to make a cross correlation when using the FFT to speed up (in
contrast to the normal O(n^2) method). First I did not zero-pad
because changes from the pictures are small. It worked. Then I added
zero-padding around my pictures (they are about 600x400 pixels so now
with zero-padding they are about 1200x800 pixels). Then all the
results are wrong because the images from the digital camera I take
have a high DC offset (around value of 1000). So the padded areas are
totally dark and when there is the picture then the values becomes
suddenly around 1000-4000. So I get very wrong result. How do I zero
pad in a right way?

Thank you for your help!
Frederick
On 3 Jul, 17:15, Frederick Mengin <FrederickMen...@gmx.de> wrote:
> Hello, > > I try to make a cross correlation when using the FFT to speed up (in > contrast to the normal O(n^2) method). First I did not zero-pad > because changes from the pictures are small. It worked. Then I added > zero-padding around my pictures (they are about 600x400 pixels so now > with zero-padding they are about 1200x800 pixels). Then all the > results are wrong because the images from the digital camera I take > have a high DC offset (around value of 1000). So the padded areas are > totally dark and when there is the picture then the values becomes > suddenly around 1000-4000. So I get very wrong result. How do I zero > pad in a right way?
Sounds like at least parts of the problem is visualization? Instead of plotting the correlation, try and plot log(abs(Cxy)). Rune
Hello Rune,

On 3 Jul., 17:40, Rune Allnor <all...@tele.ntnu.no> wrote:

> Sounds like at least parts of the problem is visualization? > Instead of plotting the correlation, try and plot log(abs(Cxy)).
No, it is really not. I did plot it on log scale (although tried lin, sqrt, etc. scale, all the same). When I do the zero padding the maximum intensity is in the corners of the image (e.g. 0,0, width-1,0, 0,height-1, width-1,height-1) which indicates the image is still, but it has moved some pixels (about +8, +8 pixels in my example). This is really weird. Bye, Frederick
Frederick Mengin wrote:
> Hello, > > I try to make a cross correlation when using the FFT to speed up (in > contrast to the normal O(n^2) method). First I did not zero-pad > because changes from the pictures are small. It worked. Then I added > zero-padding around my pictures (they are about 600x400 pixels so now > with zero-padding they are about 1200x800 pixels). Then all the > results are wrong because the images from the digital camera I take > have a high DC offset (around value of 1000). So the padded areas are > totally dark and when there is the picture then the values becomes > suddenly around 1000-4000. So I get very wrong result. How do I zero > pad in a right way? > > Thank you for your help!
I think you need to pad with the offset value. That's your effective zero. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
> I think you need to pad with the offset value. That's your effective zero. > > Jerry
Yeah, that should do it. Zero padding an image that has a a high DC offset is like adding a big step function in the time domain. That will result in a highly skewed spectrum in the frequency domain. To Frederick Mengin: If your results are OK without the zero padding, then that very large offset is almost certainly the source of your problem when zero padding. Think of what the cross correlation tells you: one image shifted left/right by x pixels and up/down by y pixels most closely matches the other image. With a large DC offset, you've got two images, each one of which has a huge 1000 to 0 step function in it (plus your image data). Your cross correlation is going to tell you more about those step functions than about your images. Kevin McGee
On Jul 3, 9:15 am, Jerry Avins <j...@ieee.org> wrote:
> Frederick Mengin wrote: > > Hello, > > > I try to make a cross correlation when using the FFT to speed up (in > > contrast to the normal O(n^2) method). First I did not zero-pad > > because changes from the pictures are small. It worked. Then I added > > zero-padding around my pictures (they are about 600x400 pixels so now > > with zero-padding they are about 1200x800 pixels). Then all the > > results are wrong because the images from the digital camera I take > > have a high DC offset (around value of 1000). So the padded areas are > > totally dark and when there is the picture then the values becomes > > suddenly around 1000-4000. So I get very wrong result. How do I zero > > pad in a right way? > > > Thank you for your help! >
.> I think you need to pad with the offset value. That's your effective zero.
> > Jerry > -- > Engineering is the art of making what you want from things you can get. > &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
I think that's close, but you might want to subtract the mean of the image from the image and go back to extending with zeros. Dale B. Dalrymple