Filters are easy


In [2]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from scipy.ndimage import convolve

In [3]:
# loading image
img = mpimg.imread('i/super_mario_head.png')
plt.imshow(img)


Out[3]:
<matplotlib.image.AxesImage at 0x7f63681529e8>

In [4]:
# cutting the image
eye_brow = img[100:150,150:200,]
plt.imshow(eye_brow,interpolation='nearest')


Out[4]:
<matplotlib.image.AxesImage at 0x7f6366ca91d0>

Kernels


In [5]:
kernel_edge_detect3 = np.array([[-1.,-1.,-1.],
                                [-1.,8.,-1.],
                                [-1.,-1.,-1.]])

kernel_sharpen2 = np.array([[-1.,-1.,-1.],
                           [-1.,9.,-1.],
                           [-1.,-1.,-1.]])

kernel_blur = np.array([[1.,1.,1.],
                        [1.,1.,1.],
                        [1.,1.,1.]])

In [6]:
img_edge_detect = convolve(eye_brow[:,:,0], kernel_edge_detect3)
img_sharpen = convolve(eye_brow[:,:,0], kernel_sharpen2)
img_blur = convolve(eye_brow[:,:,0], kernel_blur)

# creates sub plots of 15x15
f, (plt1, plt2, plt3, plt4) = plt.subplots(1, 4,figsize=(15,15))

plt1.set_title('Original');plt1.imshow(eye_brow[:,:,0],cmap='gray', interpolation='nearest');
# showing each channel img[x,y,color_plane] 
plt2.axis('off');plt2.set_title('Edge detect');plt2.imshow(img_edge_detect,cmap='gray', interpolation='nearest');
plt3.axis('off');plt3.set_title('Sharpen');plt3.imshow(img_sharpen,cmap='gray', interpolation='nearest');
plt4.axis('off');plt4.set_title('Blur');plt4.imshow(img_blur,cmap='gray', interpolation='nearest');


Convolution it's a simple operation

You can apply filters using convolution even with ffmpeg