5

# 2D Cross-Correlation between Images

Unsolved
###### Signal Processing

Difficulty: 2 | Problem written by mesakarghm
Write a function xcorr(x,y) which computes the cross-correlation to find the location of a template (y) in a noisy image (x).
The output of the function should be a tuple(a,b) representing the location of the template in the noisy image.

Feel free to use any library/function you see fit to achieve this task.

##### Sample Input:
<class 'list'>
x: [[1, 2, 3], [4, 5, 6]]
<class 'list'>
y: [[1, 2, 3], [4, 5, 6]]

##### Expected Output:
<class 'tuple'>
(2, 1)

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Have an issue, the MLPro support team is available 24X7 to Premium users.

##### This is a premium feature. To access this and other such features, click on upgrade below.

abhishek_kumar • 3 months, 1 week ago

1

from scipy import signal
import numpy as np
def xcorr(x,y):
corr = signal.correlate2d(x,y,boundary='symm', mode='same')
b,a = np.unravel_index(np.argmax(corr), corr.shape)
return (a,b)


Basically, this function is being used to locate a portion of the image on a real image.

It works on the principle of Fourier transformation of an image where the spatial format of the image donor provides us with much information.

Fourier format is easy to process.

For achieving more compact image representation

referecne: