How To Find Correlation Between Two Images Using Numpy
This is inspired by this question.
I'm trying to find correlation between two grayscale images using Numpy. Using SciPy's
correlate2d we can find this. I have found Numpy's
corrcoef but results are different when I compared with
correlate2d. Hence this question- Is there
correlate2d equivalent in Numpy?
As far as I can tell, this produces the same result as
img2 are 2d arrays representing greyscale (i.e. single-channel) images:
import numpy as np pad = np.max(img1.shape) // 2 fft1 = np.fft.fft2(np.pad(img1, pad)) fft2 = np.fft.fft2(np.pad(img2, pad)) prod = fft1 * fft2.conj() result_full = np.fft.fftshift(np.fft.ifft2(prod)) corr = result_full.real[1+pad:-pad+1, 1+pad:-pad+1]
The single-pixel cropping adjustment is not very elegant but that's FFTs for you: fiddly.
I just want to say that
scipy is perfectly fine to use and I strongly recommend it. Having said that, this approach does seem to be a lot faster for the single case I tried.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module