55import numpy as np
66from cv2 import COLOR_BGR2GRAY , cvtColor , imread
77from numpy import array , uint8
8+ from os import getenv
89from PIL import Image
910
1011from digital_image_processing import change_contrast as cc
1920from digital_image_processing .filters import sobel_filter as sob
2021from digital_image_processing .resize import resize as rs
2122
22- img = imread (r"digital_image_processing/image_data/lena_small.jpg" )
23+ # Define common image paths
24+ LENA_SMALL_PATH = "digital_image_processing/image_data/lena_small.jpg"
25+ LENA_PATH = "digital_image_processing/image_data/lena.jpg"
26+
27+ img = imread (LENA_SMALL_PATH )
2328gray = cvtColor (img , COLOR_BGR2GRAY )
2429
2530
2631# Test: convert_to_negative()
2732def test_convert_to_negative ():
2833 negative_img = cn .convert_to_negative (img )
29- # assert negative_img array for at least one True
3034 assert negative_img .any ()
3135
3236
3337# Test: change_contrast()
3438def test_change_contrast ():
35- with Image .open ("digital_image_processing/image_data/lena_small.jpg" ) as img :
36- # Work around assertion for response
39+ with Image .open (LENA_SMALL_PATH ) as img :
3740 assert str (cc .change_contrast (img , 110 )).startswith (
3841 "<PIL.Image.Image image mode=RGB size=100x100 at"
3942 )
@@ -42,17 +45,14 @@ def test_change_contrast():
4245# canny.gen_gaussian_kernel()
4346def test_gen_gaussian_kernel ():
4447 resp = canny .gen_gaussian_kernel (9 , sigma = 1.4 )
45- # Assert ambiguous array
4648 assert resp .all ()
4749
4850
4951# canny.py
5052def test_canny ():
51- canny_img = imread ("digital_image_processing/image_data/lena_small.jpg" , 0 )
52- # assert ambiguous array for all == True
53+ canny_img = imread (LENA_SMALL_PATH , 0 )
5354 assert canny_img .all ()
5455 canny_array = canny .canny (canny_img )
55- # assert canny array for at least one True
5656 assert canny_array .any ()
5757
5858
@@ -83,52 +83,30 @@ def test_sepia():
8383 assert sepia .all ()
8484
8585
86- def test_burkes (file_path : str = "digital_image_processing/image_data/lena_small.jpg" ):
87- burkes = bs .Burkes (imread (file_path , 1 ), 120 )
88- burkes .process ()
89- assert burkes .output_img .any ()
86+ def test_burkes ():
87+ burkes_img = bs .Burkes (imread (LENA_SMALL_PATH , 1 ), 120 )
88+ burkes_img .process ()
89+ assert burkes_img .output_img .any ()
9090
9191
92- def test_nearest_neighbour (
93- file_path : str = "digital_image_processing/image_data/lena_small.jpg" ,
94- ):
95- nn = rs .NearestNeighbour (imread (file_path , 1 ), 400 , 200 )
96- nn .process ()
97- assert nn .output .any ()
92+ def test_nearest_neighbour ():
93+ nn_img = rs .NearestNeighbour (imread (LENA_SMALL_PATH , 1 ), 400 , 200 )
94+ nn_img .process ()
95+ assert nn_img .output .any ()
9896
9997
10098def test_local_binary_pattern ():
101- # pull request 10161 before:
102- # "digital_image_processing/image_data/lena.jpg"
103- # after: "digital_image_processing/image_data/lena_small.jpg"
104-
105- from os import getenv # Speed up our Continuous Integration tests
106-
107- file_name = "lena_small.jpg" if getenv ("CI" ) else "lena.jpg"
108- file_path = f"digital_image_processing/image_data/{ file_name } "
109-
110- # Reading the image and converting it to grayscale
99+ # Use smaller image in CI environment for faster tests
100+ file_path = LENA_SMALL_PATH if getenv ("CI" ) else LENA_PATH
111101 image = imread (file_path , 0 )
112102
113- # Test for get_neighbors_pixel function() return not None
114- x_coordinate = 0
115- y_coordinate = 0
116- center = image [x_coordinate ][y_coordinate ]
117-
118- neighbors_pixels = lbp .get_neighbors_pixel (
119- image , x_coordinate , y_coordinate , center
120- )
121-
103+ # Test get_neighbors_pixel function
104+ neighbors_pixels = lbp .get_neighbors_pixel (image , 0 , 0 , image [0 ][0 ])
122105 assert neighbors_pixels is not None
123106
124- # Test for local_binary_pattern function()
125- # Create a numpy array as the same height and width of read image
107+ # Test local_binary_pattern function
126108 lbp_image = np .zeros ((image .shape [0 ], image .shape [1 ]))
127-
128- # Iterating through the image and calculating the local binary pattern value
129- # for each pixel.
130109 for i in range (image .shape [0 ]):
131110 for j in range (image .shape [1 ]):
132111 lbp_image [i ][j ] = lbp .local_binary_value (image , i , j )
133-
134112 assert lbp_image .any ()
0 commit comments