8
8
import numpy as np
9
9
import matplotlib .pyplot as plt
10
10
11
- import cv2
12
- import numpy as np
13
-
14
11
def add_gaussian_noise (
15
12
image_path : str ,
16
13
mean : float = 0 ,
17
14
stddev : float = 0.5
18
15
) -> np .ndarray :
16
+ """Applies gaussian noise to an image.
17
+
18
+ Args:
19
+ image_path (str): Path to the input image.
20
+ mean (float, optional): Mean of the gaussian noise. Defaults to 0.
21
+ stddev (float, optional): Starndar deviation of the gaussian noise.
22
+ Defaults to 0.5.
23
+
24
+ Returns:
25
+ np.ndarray: Image with gaussian noise of mean "mean" and standard
26
+ deviation "stddev".
27
+ """
19
28
# Read the image
20
29
image : np .ndarray = cv2 .imread (image_path )
30
+
31
+ # Apply the noise
21
32
noise = np .random .normal (mean , stddev , image .shape ).astype (np .uint8 )
22
33
noisy_image = cv2 .add (image , noise )
34
+
23
35
return noisy_image
24
36
25
37
def apply_sobel_filter (
@@ -114,7 +126,7 @@ def apply_sobel_filter(
114
126
plt .imshow (sobel_combined_uint8 , cmap = 'gray' )
115
127
plt .axis ('off' )
116
128
117
- # plt.show()
129
+ plt .show ()
118
130
119
131
return (gray_img , noisy_img , sobel_x_uint8 , sobel_y_uint8 ,
120
132
sobel_combined_uint8 )
@@ -127,7 +139,10 @@ def apply_sobel_filter(
127
139
gaussian_stddev : float = 0.5
128
140
img_name : str = 'car'
129
141
img_ext : str = 'jpg'
142
+
143
+ # Don't touch from this line
130
144
img_path : str = f'src/imgs/{ img_name } .{ img_ext } '
145
+
131
146
gray , noisy , sobel_x , sobel_y , sobel_combined = \
132
147
apply_sobel_filter (img_path , salt_probability , pepper_probability )
133
148
0 commit comments