In [1]:
import random
import numpy as np
import scipy.ndimage.filters as filters
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# This is a bit of magic to make matplotlib figures appear inline in the notebook
# rather than in a new window.
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
# Some more magic so that the notebook will reload external python modules;
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
Let us take a look at the image we want to work on
In [2]:
img = mpimg.imread('images/einstein.png')
img_width, img_height = img.shape
imgplot1 = plt.imshow(img)
Now let us blur the image
In [4]:
img_blur = filters.gaussian_filter(img.reshape(img_width*img_height, 1), 4.0).reshape(img_width, img_height)
img_blur = img_blur + np.random.normal(0, 0.001, (img_width, img_height))
imgplot2 = plt.imshow(img_blur)
In [ ]: