import matplotlib.pyplot as plt
import numpy as np
from skimage.io import imread
# Load image:
input_pixels = imread('resources/puppy.jpg')
# # Box Blur kernel
kernel = [[0.1111, 0.1111, 0.1111],
[0.1111, 0.1111, 0.1111],
[0.1111, 0.1111, 0.1111]]
# # Middle of the kernel
offset = len(kernel) // 2
# # Create output image
output_image = np.zeros_like(input_pixels)
# # Compute convolution between intensity and kernels
for row in range(offset, input_pixels.shape[0] - offset):
for col in range(offset, input_pixels.shape[1] - offset):
accumulator = [0.0, 0.0, 0.0]
pixel_rgb = input_pixels[(row-1):(row+2),(col-1):(col+2)];
accumulator[0] = np.sum(kernel * pixel_rgb[0])
accumulator[1] = np.sum(kernel * pixel_rgb[1])
accumulator[2] = np.sum(kernel * pixel_rgb[2])
output_image[row,col] = accumulator
plt.subplot(121)
plt.axis('off')
plt.imshow(input_pixels)
plt.subplot(122)
plt.axis('off')
plt.imshow(output_image)
<matplotlib.image.AxesImage at 0x819e81c90>