-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateMotionBlur.py
58 lines (40 loc) · 1.29 KB
/
CreateMotionBlur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 23 15:28:43 2019
@author: Olivier
"""
import cv2
import numpy as np
from matplotlib import pyplot as plt
imgRGB = cv2.imread('input2.jpg')
img = cv2.cvtColor(imgRGB, cv2.COLOR_BGR2GRAY)
#cv2.imshow('Original', img)
sigma = 1
dimension= img.shape
noise = np.random.normal(0, sigma, size=(dimension[0], dimension[1]))
noise = noise.reshape(img.shape[0],img.shape[1]).astype('uint8')
print (noise)
size = 150
# generating the kernel
kernel_motion_blur = np.zeros((size, size))
kernel_motion_blur[int((size-1)), :] = np.ones(size)
kernel_motion_blur = kernel_motion_blur / size
# applying the kernel to the input image
imageWithMotionBlur = cv2.filter2D(img, -1, kernel_motion_blur)
output2 = cv2.filter2D(img, -1, kernel_motion_blur2)
#Adding the noise to the blurred image
output3 = cv2.add(imageWithMotionBlur, noise)
noisy_output = cv2.cvtColor(output3, cv2.COLOR_GRAY2RGB)
#Displaying the different Images
print("Original Image")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_GRAY2RGB))
plt.show()
print("\n\n\nImage with Motion Blur")
plt.imshow(cv2.cvtColor(imageWithMotionBlur, cv2.COLOR_GRAY2RGB))
plt.show()
print("\n\n\nMotion Blur + Noise")
plt.imshow(noisy_output)
plt.show()
#plt.imshow(output3)
#cv2.imshow('Motion Blur2', output2)
#cv2.waitKey(30000)