-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgaussian_image_test.py
More file actions
executable file
·60 lines (43 loc) · 1.46 KB
/
gaussian_image_test.py
File metadata and controls
executable file
·60 lines (43 loc) · 1.46 KB
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
59
#! /usr/bin/env python
import cv2
import numpy as np
import matplotlib.pyplot as plt
import time
from image_processor import *
print (TCOLORS.PURPLE + "Unit Test: Applying a Gaussian Blure on an image" + TCOLORS.NORMAL)
SIGMA = 1
ENVELOPE_SIZE = 5
img = cv2.imread(FILENAME)
gray = rgb2gray(img)
width = len(gray)
height = len(gray[0])
print "Image Width: %d Image Height: %d" % (len(gray), len(gray[0]))
print "Sigma: %d" % SIGMA
print "Envelope Size: %d" % ENVELOPE_SIZE
print "Generating Gaussian Envelope...",
start_time = time.time()
gaussian_envelope = gen_deviation_array(SIGMA, ENVELOPE_SIZE)
elapsed_time = time.time() - start_time
print "Done: Elapsed Time: %.3f" % elapsed_time
print "Gaussian Envelope: %s" % str(gaussian_envelope)
print "Using Open CV to apply gaussian blur...",
start_time = time.time()
blur = cv2.GaussianBlur(gray,(SIGMA,SIGMA),0)
elapsed_time = time.time() - start_time
print "Done: Elapsed Time: %.3f" % elapsed_time
print "Using custom algorithm to apply gaussian blur...",
start_time = time.time()
gaussian_blure = two_d_gaussian_blure(gray, gaussian_envelope)
elapsed_time = time.time() - start_time
print "Done: Elapsed Time: %.3f" % elapsed_time
fig = plt.figure()
a=fig.add_subplot(1,3,1)
plt.title("Original")
plt.imshow(gray, cmap='Greys_r')
a=fig.add_subplot(1,3,2)
plt.title("Opencv Gaussian Blur")
plt.imshow(blur, cmap='Greys_r')
a=fig.add_subplot(1,3,3)
plt.title("Gaussian Blur")
plt.imshow(gaussian_blure, cmap='Greys_r')
plt.show()