# How to do phase correlation to estimate the geometrical shifts between two images?

## Phase Correlation¶

### In this notebook I will show how to use Fourier Transform to find the shifts between two misaligned images, then I will show how to use Bi-linear interpolation to align them.¶

In [1]:
```import numpy as np
import matplotlib.pyplot as plt
import pyfits
```

#### Let's load a continuum image taken from the MURAM simulation of a plage region.¶

In [3]:
```path = '/home/fatima/Desktop/solar_orbiter_project/codes/targets/distortion/'
sim = pyfits.getdata(path+'synth_continuum_profile.fits')
```
In [8]:
```fig = plt.figure(figsize=(15,10))
plt.imshow(sim,cmap='gray')
plt.colorbar()
```
Out[8]:
`<matplotlib.colorbar.Colorbar at 0x7f0d1a008bd0>`

#### Let us introduce vertical and horizontal shifts.¶

In [42]:
```def shift(x,y,del_x,del_y):
x_s = x + del_x
y_s = y + del_y
return x_s, y_s
```
In [5]:
```from scipy import interpolate
```
In [12]:
```size = sim.shape[0]
x = y = np.arange(size)

F= interpolate.interp2d(x,y,sim, kind='linear')
```
In [15]:
```shifted = np.zeros((size,size))
for j in range(size):
for i in range(size):
i_s, j_s = shift(i,j,10,3)
shifted[j,i] = F(i_s,j_s)
```
In [16]:
```fig=plt.figure(figsize=(25,15))
`<matplotlib.image.AxesImage at 0x7f0d19b54790>`