ncempy.algo.multicorr_funcs module¶
Module to correlate two images, functionally written.
- ncempy.algo.multicorr_funcs.dftUpsample(image_corr, upsample_factor, xy_shift)[source]¶
This performs a matrix multiply DFT around a small neighboring region of the initial correlation peak. By using the matrix multiply DFT to do the Fourier upsampling, the efficiency is greatly improved. This is adapted from the subfunction dftups found in the dftregistration function on the Matlab File Exchange.
The matrix multiplication DFT is from Manuel Guizar-Sicairos, Samuel T. Thurman, and James R. Fienup, “Efficient subpixel image registration algorithms,” Opt. Lett. 33, 156-158 (2008). http://www.sciencedirect.com/science/article/pii/S0045790612000778
- Parameters:
- Returns:
image_upsample – Upsampled image from region around correlation peak.
- Return type:
ndarray
- ncempy.algo.multicorr_funcs.imageShifter(g1, xy_shift)[source]¶
Multiply im by a plane wave that has the real space effect of shifting ifft2(G2) by [x, y] pixels.
- Parameters:
g1 (complex ndarray) – The Fourier transform of an image.
xy_shift (list) – A two element list of the shifts along each axis.
- Returns:
G2shift – Fourier shifted image FFT
- Return type:
complex ndarray
Example
>> shiftIm0 = np.real(np.fft.ifft2(multicorr.imageShifter(np.fft.fft2(im0),[11.1,22.2]))) >> plt.imshow(shiftIm0)
- ncempy.algo.multicorr_funcs.initial_correlation_image(g1, g2, method='cross', verbose=False)[source]¶
Generate correlation image at initial resolution using the method specified.
- Parameters:
g1 (complex ndarray) – Fourier transform of reference image.
g2 (complex ndarray) – Fourier transform of the image to register (the kernel).
method (str, optional) – The correlation method to use. Must be ‘phase’ or ‘cross’ or ‘hybrid’ (default = ‘cross’)
verbose (bool, default is False) – Print output.
- Returns:
imageCorr – Correlation array which has not yet been inverse Fourier transformed.
- Return type:
ndarray complex
- ncempy.algo.multicorr_funcs.upsampleFFT(image_init, upsample_factor)[source]¶
This does a Fourier upsample of the imageInit. imageInit is the Fourier transform of the correlation image. The function returns the real space correlation image that has been Fourier upsampled by the upsample_factor. An upsample factor of 2 is generally sufficient.
The way it works is that it embeds imageInit in a larger array of zeros, then does the inverse Fourier transform to return the Fourier upsampled image in real space.
- Parameters:
image_init (ndarray complex) – The image to be Fourier upsampled. This should be in the Fourier domain.
upsample_factor (int) – THe upsample factor (usually 2).
- Returns:
imageUpsampleReal – The inverse Fourier transform of imageInit upsampled by the upsampleFactor.
- Return type:
ndarray complex
OLD¶
imageSize = imageInit.shape imageUpsample = np.zeros(tuple((i*upsampleFactor for i in imageSize))) + 0j imageUpsample[:imageSize[0], :imageSize[1]] = imageInit imageUpsample = np.roll(np.roll(imageUpsample, -int(imageSize[0]/2), 0), -int(imageSize[1]/2),1) imageUpsampleReal = np.real(np.fft.ifft2(imageUpsample)) return imageUpsampleReal
- ncempy.algo.multicorr_funcs.upsampled_correlation(image_corr, upsample_factor, verbose=False)[source]¶
Upsamples the correlation image by a set integer factor upsample_factor. If upsample_factor == 2, then it is naively Fourier upsampled. If the upsample_factor is higher than 2, then it uses dftUpsample, which is a more efficient way to Fourier upsample the image.