image_registration Package

image_registration Package

This is an Astropy affiliated package.

Functions

chi2_shift(im1, im2[, err, upsample_factor, ...]) Find the offsets between image 1 and image 2 using the DFT upsampling method
chi2_shift_iterzoom(im1, im2[, err, ...]) Find the offsets between image 1 and image 2 using an iterative DFT
chi2n_map(im1, im2[, err, boundary, ...])
Parameters:
cross_correlation_shifts(image1, image2[, ...]) Use cross-correlation and a 2nd order taylor expansion to measure the
cross_correlation_shifts_FITS(fitsfile1, ...) Determine the shift between two FITS images using the cross-correlation technique.
register_images(im1, im2[, usfac, ...]) Sub-pixel image registration (see dftregistration for lots of details)
test([package, test_path, args, plugins, ...]) Run the tests using py.test.

register_images Module

image_registration.register_images Module

Functions

register_images(im1, im2[, usfac, ...]) Sub-pixel image registration (see dftregistration for lots of details)
image_registration.register_images.register_images(im1, im2, usfac=1, return_registered=False, return_error=False, zeromean=True, DEBUG=False, maxoff=None, nthreads=1, use_numpy_fft=False)[source] [edit on github]

Sub-pixel image registration (see dftregistration for lots of details)

Parameters:

im1 : np.ndarray

im2 : np.ndarray

The images to register.

usfac : int

upsampling factor; governs accuracy of fit (1/usfac is best accuracy)

return_registered : bool

Return the registered image as the last parameter

return_error : bool

Does nothing at the moment, but in principle should return the “fit error” (it does nothing because I don’t know how to compute the “fit error”)

zeromean : bool

Subtract the mean from the images before cross-correlating? If no, you may get a 0,0 offset because the DC levels are strongly correlated.

maxoff : int

Maximum allowed offset to measure (setting this helps avoid spurious peaks)

DEBUG : bool

Test code used during development. Should DEFINITELY be removed.

Returns:

dx,dy : float,float

REVERSE of dftregistration order (also, signs flipped) for consistency with other routines. Measures the amount im2 is offset from im1 (i.e., shift im2 by these #’s to match im1)

chi2_shifts Module

image_registration.chi2_shifts Module

Chi^2 shifts

Various tools for calculating shifts based on the chi^2 method

Functions

chi2_shift(im1, im2[, err, upsample_factor, ...]) Find the offsets between image 1 and image 2 using the DFT upsampling method
chi2_shift_iterzoom(im1, im2[, err, ...]) Find the offsets between image 1 and image 2 using an iterative DFT
chi2n_map(im1, im2[, err, boundary, ...])
Parameters:

cross_correlation_shifts Module

image_registration.cross_correlation_shifts Module

Functions

cross_correlation_shifts(image1, image2[, ...]) Use cross-correlation and a 2nd order taylor expansion to measure the
cross_correlation_shifts_FITS(fitsfile1, ...) Determine the shift between two FITS images using the cross-correlation technique.
image_registration.cross_correlation_shifts.cross_correlation_shifts(image1, image2, errim1=None, errim2=None, maxoff=None, verbose=False, gaussfit=False, return_error=False, zeromean=True, **kwargs)[source] [edit on github]

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

zeromean : bool

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

verbose: bool

Print out extra messages?

gaussfit : bool

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