cophus / scanning-drift-corr

Correction of nonlinear and linear scanning probe artifacts using orthogonal scan pairs.
13 stars 6 forks source link

Reason for using "symmetric" in ifft? #3

Closed thomasaarholt closed 5 years ago

thomasaarholt commented 5 years ago

Hi Colin,

Do you have a specific reason for using the "symmetric" argument in the ifft2 code?

https://github.com/cophus/scanning-drift-corr/blob/2ae74ef40d9db247670021623fdf12881606f4c7/matlab/SPmerge01linear.m#L106

cophus commented 5 years ago

Hi Thomas. Yes! This measurement is for correlation of the two images, given by the real value of the output. In matlab there are two identical ways to produce this result:

Icorr = real( ifft2( ... ) ); or Icorr = ifft2( ... , 'symmetric');

The first option computes the real and imaginary outputs and then throws away the imaginary part. The second way only computes the needed real component (I think) and thus is faster.

thomasaarholt commented 5 years ago

Cool, that's fine then! Googling/Stackoverflow was remarkably unhelpful in giving an explanation of how to translate that into numpy code.

In case anyone ends up in this thread from google, in numpy you do: np.fft.ifft2(fft_of_A).real (specifically not np.fft.irfft2(fft_of_A), which is an ifft2 of a real fft_of_A)