def FFTPhaseCorrelation(FFTFixed, FFTMoving, delete_input=False):
    '''
    Returns the phase shift correlation of the FFT's of two images. 
    
    Dimensions of Fixed and Moving images must match
    
    :param ndarray FixedImage: grayscale image
    :param ndarray MovingImage: grayscale image
    :returns: Correlation image of the FFT's.  Light pixels indicate the phase is well aligned at that offset.
    :rtype: ndimage
    
    '''

    if(not (FFTFixed.shape == FFTMoving.shape)):
        # TODO, we should pad the smaller image in this case to allow the comparison to continue
        raise ValueError("ImagePhaseCorrelation: Fixed and Moving image do not have same dimension")
 

    #--------------------------------
    # This is here in case this function ever needs to be revisited.  Scipy is a lot faster working with in-place operations so this
    # code has been obfuscated more than I like
    # FFTFixed = fftpack.rfft2(FixedImage)
    # FFTMoving = fftpack.rfft2(MovingImage)
    # conjFFTFixed = conj(FFTFixed)
    # Numerator = conjFFTFixed * FFTMoving
    # Divisor = abs(conjFFTFixed * FFTMoving)
    # T = Numerator / Divisor
    # CorrelationImage = real(fftpack.irfft2(T))
    #--------------------------------

    conjFFTFixed = np.conjugate(FFTFixed)
    if delete_input:
        del FFTFixed

    conjFFTFixed *= FFTMoving
    
    if delete_input:
        del FFTMoving   

    conjFFTFixed /= np.absolute(conjFFTFixed)  # Numerator / Divisor

    CorrelationImage = np.real(fftpack.irfft2(conjFFTFixed))
    del conjFFTFixed

    return CorrelationImage 
Exemple #2
0
def ift(psi):
    """Go from spectral space to physical space."""
    return irfft2(psi, axes=(-2, -1))
def ift(psi):
    """Go from spectral space to physical space."""
    return irfft2(psi, axes=(-2,-1))