cross_correlation_shifts

image_registration.cross_correlation_shifts(image1, image2, errim1=None, errim2=None, maxoff=None, verbose=False, gaussfit=False, return_error=False, zeromean=True, **kwargs)[source]

Use cross-correlation and a 2nd order taylor expansion to measure the offset between two images

Given two images, calculate the amount image2 is offset from image1 to sub-pixel accuracy using 2nd order taylor expansion.

Parameters:
image1: np.ndarray

The reference image

image2: np.ndarray

The offset image. Must have the same shape as image1

errim1: np.ndarray [optional]

The pixel-by-pixel error on the reference image

errim2: np.ndarray [optional]

The pixel-by-pixel error on the offset image.

maxoff: int

Maximum allowed offset (in pixels). Useful for low s/n images that you know are reasonably well-aligned, but might find incorrect offsets due to edge noise

zeromeanbool

Subtract the mean from each image before performing cross-correlation?

verbose: bool

Print out extra messages?

gaussfitbool

Use a Gaussian fitter to fit the peak of the cross-correlation?

return_error: bool

Return an estimate of the error on the shifts. WARNING: I still don’t understand how to make these agree with simulations. The analytic estimate comes from http://adsabs.harvard.edu/abs/2003MNRAS.342.1291Z At high signal-to-noise, the analytic version overestimates the error by a factor of about 1.8, while the gaussian version overestimates error by about 1.15. At low s/n, they both UNDERestimate the error. The transition zone occurs at a total S/N ~ 1000 (i.e., the total signal in the map divided by the standard deviation of the map - it depends on how many pixels have signal)

**kwargs are passed to correlate2d, which in turn passes them to convolve.
The available options include image padding for speed and ignoring NaNs.

References

From http://solarmuri.ssl.berkeley.edu/~welsch/public/software/cross_cor_taylor.pro

Examples

>>> import numpy as np
>>> im1 = np.zeros([10,10])
>>> im2 = np.zeros([10,10])
>>> im1[4,3] = 1
>>> im2[5,5] = 1
>>> import image_registration
>>> yoff,xoff = image_registration.cross_correlation_shifts(im1,im2)
>>> im1_aligned_to_im2 = np.roll(np.roll(im1,int(yoff),1),int(xoff),0)
>>> assert (im1_aligned_to_im2-im2).sum() == 0