# -*- coding: utf-8 -*-
"""Linear_fourier_filter_exercise.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1KQlihNHOyF1_p6he0IWGrdA23wIfoUvA
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import ascent, face

# Change this to an image of your choosing!
#image = ascent()  # Boring staircase
image = face().mean(axis=2) # Cute little friend face


image = (image - image.mean()) / image.std()
n_x, n_y = image.shape

plt.imshow(image, cmap='Greys_r')

from numpy.fft import fft2, ifft2, fftshift

image_ft = fftshift(fft2(image))
amp = image_ft.real
phase = np.arctan2(image_ft.imag, image_ft.real)

X,Y = np.meshgrid( np.linspace(-.5, .5, n_y), np.linspace(-.5,.5, n_x) )
k = (X**2 + Y**2)**.5

# Change this filter
filt = np.ones_like(image)

# Example filters
#filt = np.exp(-100*k)

#filt = k < .01

#filt = k > .05

#filt = np.sin(100*k**2)

#x_sh,y_sh = 100,100
#filt = np.exp( -1j *2*np.pi * ((x_sh * X) + (y_sh * Y)))


image_filtered = ifft2( fftshift(image_ft * filt) ).real

plt.imshow(image_filtered, cmap='Greys_r')
plt.show()

