1
1
"""
2
2
PyTest's for Digital Image Processing
3
3
"""
4
+
5
+ # add change_contrast
6
+ from PIL import Image
7
+ import digital_image_processing .change_contrast as cc
8
+ # add canny
9
+ import digital_image_processing .edge_detection .canny as canny
10
+ import cv2
11
+ # add gen_gaussian
12
+ from cv2 import imread , cvtColor , COLOR_BGR2GRAY , imshow , waitKey
13
+ from numpy import array , pi , mgrid , exp , square , zeros , ravel , dot , uint8
14
+ import digital_image_processing .filters .gaussian_filter as gg
15
+ # add convolve
16
+ import digital_image_processing .filters .convolve as conv
17
+ # add median
18
+ import digital_image_processing .filters .median_filter as med
19
+ # add sobel_filter
20
+ import digital_image_processing .filters .sobel_filter as sob
21
+ # add img
22
+ img = imread (r'digital_image_processing/image_data/lena.jpg' )
23
+ # add gray
24
+ gray = cvtColor (img , COLOR_BGR2GRAY )
25
+
4
26
# Test: change_contrast()
5
27
def test_change_contrast ():
6
- from PIL import Image
7
- import digital_image_processing .change_contrast as cc
8
28
# Image object
9
29
with Image .open ("digital_image_processing/image_data/lena.jpg" ) as img :
10
30
# Work around assertion for response
11
31
assert str (cc .change_contrast (img , 110 )).startswith ('<PIL.Image.Image image mode=RGB size=512x512 at' )
12
32
13
33
# Test: canny.gen_gaussian_kernel()
14
34
def test_gen_gaussian_kernel ():
15
- # import canny
16
- import digital_image_processing .edge_detection .canny as cc
17
35
# get ambiguous array
18
- resp = cc .gen_gaussian_kernel (9 , sigma = 1.4 )
36
+ resp = canny .gen_gaussian_kernel (9 , sigma = 1.4 )
19
37
# Assert ambiguous array
20
38
assert resp .all ()
21
39
22
40
# Test: canny()
23
41
def test_canny ():
24
- # import reqs
25
- import cv2
26
- import digital_image_processing .edge_detection .canny as cc
27
42
# read image in gray
28
- img = cv2 . imread ('digital_image_processing/image_data/lena.jpg' , 0 )
43
+ canny_img = imread ('digital_image_processing/image_data/lena.jpg' , 0 )
29
44
# assert ambiguos array for all == True
30
- assert img .all ()
45
+ assert canny_img .all ()
31
46
# Get canny array
32
- canny_array = cc .canny (img )
47
+ canny_array = canny .canny (canny_img )
33
48
# assert canny array for at least one True
34
49
assert canny_array .any ()
35
50
36
- """
37
51
# Test: filters/gaussian_filter.py
38
- def gen_gaussian_kernel_filter():
39
- # imports
40
- from cv2 import imread, cvtColor, COLOR_BGR2GRAY, imshow, waitKey
41
- from numpy import pi, mgrid, exp, square, zeros, ravel, dot, uint8
42
- # import gaussian filter file
43
- import digital_image_processing.filters.gen_gaussian_kernel as gg
44
-
45
- """
52
+ def test_gen_gaussian_kernel_filter ():
53
+ # Filter 5x5
54
+ assert gg .gaussian_filter (gray , 5 , sigma = 0.9 ).all ()
55
+
56
+ def test_convolve_filter ():
57
+ # laplace diagonals
58
+ Laplace = array ([[0.25 , 0.5 , 0.25 ], [0.5 , - 3 , 0.5 ], [0.25 , 0.5 , 0.25 ]])
59
+ res = conv .img_convolve (gray , Laplace ).astype (uint8 )
60
+ assert res .any ()
61
+
62
+ def test_median_filter ():
63
+ assert med .median_filter (gray , 3 ).any ()
64
+
65
+ def test_sobel_filter ():
66
+ grad , theta = sob .sobel_filter (gray )
67
+ assert grad .any () and theta .any ()
0 commit comments