def ImagePhaseCorrelation(FixedImage, MovingImage): ''' 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 (FixedImage.shape == MovingImage.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)) #-------------------------------- FFTFixed = fftpack.rfft2(FixedImage) FFTMoving = fftpack.rfft2(MovingImage) return FFTPhaseCorrelation(FFTFixed, FFTMoving, True)
def ft(phi): """Go from physical space to spectral space.""" return rfft2(phi, axes=(-2, -1))