FFTNormalizedCrossCorrelation: Get location in image


I have written the following code, and obtained the correct maximum value from the FFT Normalized Cross Correlation tools in SimpleITK.
I am now wondering, how I can get this maximum value location(x,y) within the image?

Thank you

sitk::Image moving = sitk::ReadImage(“SUB.jpg”, sitk::sitkFloat32);
sitk::Image fixed = sitk::ReadImage(“IMG.jpg”, sitk::sitkFloat32);

sitk::Image out = sitk::FFTNormalizedCorrelation(fixed,moving);
out = sitk::SmoothingRecursiveGaussian(out);

sitk::MinimumMaximumImageFilter minMax;

double max = minMax.GetMaximum();

The get the translation, you need the location of the peak. Take a look at how this is done in ITKMontage:


Please find here a functioning version of FFT based translation initialization, based on the code I had previously shared:

It uses the uses a sequence of the RegionalMaxima, ConnectedComponents and LabelStatistics image filter to locate the maximum in the correlation image, and then produces a translation matrix.

Hope this helps,


Hi @blowekamp

I was able to successfully get this to work, but can a few questions about the FFT output/results.

Are the calculated peak locations w.r.t. the FFT output image or the fixed image?
(ie. if the peak location is 25,25 in space, would that be in regard to the output image or the fixed?)

As well, I am working with the following problem:

The moving image is a small section of an undeformed image. I would like to calculate the difference between its original location in the undeformed image and its new “matched” location in the deformed/fixed image.

However, I am not sure how to do this in sitk because I am still confused about the different spatial domains that are used.

Will I need to somehow resample/resize the smaller undeformed full image into the deformed image space, and find the original subimage center point in the newly resized image, then calculate the difference between that point and the FFT peak point results?

Thank you!

In the code I liked to above, a translation transform is returned which maps physical points from the fixed image to the moving image. The details of the calculation are performed in the code.

If you have any specific questions about that code please let me know.

If you are confused about the spacial domains, I suggest reading:


1 Like

So, for example, in a 2D case, if the translation calculated by FFT is [-50,80], the translation transform being returned is just applying this singular translation pair to any point (as if it is linearly changing within the image)?