I want to calc the autocorrelation of an image on a GPU. However, when I use the cupy correlate function, I get a different result than for the CPU calculation. Is it because cupyx.scipy.ndimage.correlate automatically normalizes the result by the autocorrelation of a uniform image?
import numpy as np
import scipy.signal as sc
import cupy as cp
import cupyx.scipy.ndimage as cnd
from matplotlib import pyplot as plt
ones = np.ones((128,128))
corr_cpu = sc.correlate2d(ones,ones)
corr_gpu = cnd.correlate(cp.array(ones),cp.array(ones))
plt.figure()
plt.imshow(corr_cpu)
plt.colorbar()
plt.title('Correlation CPU')
plt.figure()
plt.imshow(cp.asnumpy(corr_gpu))
plt.colorbar()
plt.title('Correlation GPU')
plt.show()
Okay found the answer: cupyx.scipy.ndimage.correlate uses mode='reflect' as default, whereas scipy.correlate uses 'constant'.
So 'constant' for cupy gives now the same result as the scipy function