88import numpy as np
99import matplotlib .pyplot as plt
1010
11- import cv2
12- import numpy as np
13-
1411def add_gaussian_noise (
1512 image_path : str ,
1613 mean : float = 0 ,
1714 stddev : float = 0.5
1815 ) -> 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+ """
1928 # Read the image
2029 image : np .ndarray = cv2 .imread (image_path )
30+
31+ # Apply the noise
2132 noise = np .random .normal (mean , stddev , image .shape ).astype (np .uint8 )
2233 noisy_image = cv2 .add (image , noise )
34+
2335 return noisy_image
2436
2537def apply_sobel_filter (
@@ -114,7 +126,7 @@ def apply_sobel_filter(
114126 plt .imshow (sobel_combined_uint8 , cmap = 'gray' )
115127 plt .axis ('off' )
116128
117- # plt.show()
129+ plt .show ()
118130
119131 return (gray_img , noisy_img , sobel_x_uint8 , sobel_y_uint8 ,
120132 sobel_combined_uint8 )
@@ -127,7 +139,10 @@ def apply_sobel_filter(
127139 gaussian_stddev : float = 0.5
128140 img_name : str = 'car'
129141 img_ext : str = 'jpg'
142+
143+ # Don't touch from this line
130144 img_path : str = f'src/imgs/{ img_name } .{ img_ext } '
145+
131146 gray , noisy , sobel_x , sobel_y , sobel_combined = \
132147 apply_sobel_filter (img_path , salt_probability , pepper_probability )
133148
0 commit comments