chi2_shift_iterzoom¶
- image_registration.chi2_shifts.chi2_shift_iterzoom(im1, im2, err=None, upsample_factor='auto', boundary='wrap', nthreads=1, use_numpy_fft=False, zeromean=False, verbose=False, return_error=True, return_chi2array=False, zoom_shape=[10, 10], rezoom_shape=[100, 100], rezoom_factor=5, mindiff=1, **kwargs)[source]¶
Find the offsets between image 1 and image 2 using an iterative DFT upsampling method combined with \(\chi^2\) to measure the errors on the fit
A simpler version of
chi2_shift()
that only computes the \(\chi^2\) array on the largest scales, then uses a fourier upsampling technique to zoom in.- Parameters:
- im1np.ndarray
- im2np.ndarray
The images to register.
- errnp.ndarray
Per-pixel error in image 2
- boundary‘wrap’,’constant’,’reflect’,’nearest’
Option to pass to map_coordinates for determining what to do with shifts outside of the boundaries.
- upsample_factorint or ‘auto’
upsampling factor; governs accuracy of fit (1/usfac is best accuracy) (can be “automatically” determined based on chi^2 error)
- zeromeanbool
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.
- verbosebool
Print error message if upsampling factor is inadequate to measure errors
- use_numpy_fftbool
Force use numpy’s fft over fftw? (only matters if you have fftw installed)
- nthreadsbool
Number of threads to use for fft (only matters if you have fftw installed)
- nfittedint
number of degrees of freedom in the fit (used for chi^2 computations). Should probably always be 2.
- zoom_shape[int,int]
Shape of iterative zoom image
- rezoom_shape[int,int]
Shape of the final output chi^2 map to use for determining the errors
- rezoom_factorint
Amount to zoom above the last zoom factor. Should be <= rezoom_shape/zoom_shape
- Returns:
- dx,dyfloat,float
Measures the amount im2 is offset from im1 (i.e., shift im2 by -1 * these #’s to match im1)
- errx,erryfloat,float
optional, error in x and y directions
- xvals,yvals,chi2n_upsampledndarray,ndarray,ndarray,
x,y positions (in original chi^2 coordinates) of the chi^2 values and their corresponding chi^2 value
- Other Parameters:
- return_errorbool
Returns the “fit error” (1-sigma in x and y) based on the delta-chi2 values
- return_chi2_arraybool
Returns the x and y shifts and the chi2 as a function of those shifts in addition to other returned parameters. i.e., the last return from this function will be a tuple (x, y, chi2)
Examples
Create a 2d array, shift it in both directions, then use chi2_shift_iterzoom to determine the shift
>>> import image_registration >>> np.random.seed(42) # so the doctest will pass >>> image = np.random.randn(50,55) >>> shifted = np.roll(np.roll(image,12,0),5,1) >>> dx,dy,edx,edy = chi2_shift_iterzoom(image, shifted, upsample_factor='auto') >>> shifted2 = image_registration.fft_tools.shift2d(image,3.665,-4.25) >>> dx2,dy2,edx2,edy2 = chi2_shift_iterzoom(image, shifted2, upsample_factor='auto')