Class for the FFT correlator

For calculating the correlation with fast Fourier Transform (FFT) a class is set up.

class piv.fft_correlator.FFTCorrelator(window_a_size, window_b_size, scale_fft='default')[source]

An FFT Correlation Class for a PIV Evaluation of two frames It uses the pyfftw library for performant FFT. This class is also responsible for calculating the Shift after the correlation.

Initialize fftw objects for FFTs with the pyfftw library

The necessary functions are loaded and memory allocated.

Parameters:
  • window_a_size – size of the interrogation window
  • window_b_size – size of the search window
  • scale_fft (str) – if set to upscale, the padding will be upscaled

If the window size does not meet the needs of the FFT function, the windows get padded with zeros.

FFTCorrelator._set_padding(windows_size, scale_fft)[source]

Set zero padding size for FFTs

By calling the function for the getting the displacement the correlation is performed as well

FFTCorrelator.get_displacement(window_a, window_b, subpixel_method='gaussian')[source]

Compute the displacement out of correlation.

First the correlation is performed and afterwards the shift is calculated. For the displacement calculation the function

find_peak(corr, method='gaussian')

Peak detection algorithm switch

After loading the correlation window an maximum finder is invoked. The correlation window is cut down to the necessary 9 points around the maximum. Afterwards the maximum is checked not to be close to the boarder of the correlation frame. This cropped window is used in along with the chosen method to interpolate the sub pixel shift. Each interpolation method returns a tuple with the sub pixel shift in x and y direction. The maximums position and the sub pixel shift are added and returned. If an error occurred during the sub pixel interpolation the shift is set to nan. Also if the interpolation method is unknown an exception in thrown.

Parameters:
  • corr – correlation window
  • method – peak finder algorithm (gaussian, centroid, parabolic, 9point)
Raises:

Sub pixel interpolation method not found

Returns:

shift in interrogation window

is called with the subpixel_method passed on as parameter. If a padding was needed, it is removed from the calculated displacement.

Parameters:
  • window_a – interrogation window
  • window_b – search window
  • subpixel_method (str) – method for peak finder
Returns:

shift in x and y direction as tuple

FFTCorrelator._evaluate_windows(window_a, window_b)[source]

Calculate the FFT of both windows, correlate and transform back.

In order to decrease the error a mean subtraction is performed. To compensate for the indexing during the FFT a FFT Shift is performed.

Parameters:
  • window_a – interrogation window
  • window_b – search window
Returns:

correlation window