In this section, we will smooth the image with a Gaussian filter. Applying the GaussianBlur function from the OpenCV library reduces the noise in our image.
We will apply it using OpenCV, as follows:
- Start by importing OpenCV and numpy:
In[1]: import cv2
In[2]: import numpy as np
- In the next step, read the input image:
In[3]: image = cv2.imread('test_image.jpg')
In[4]: lanelines_image = np.copy(image)
- Now, we will convert the image into grayscale:
In[5]: gray_conversion= cv2.cvtColor(lanelines_image, cv2.COLOR_RGB2GRAY)
- Apply GaussianBlur using the OpenCV library:
In[6]: blur_conversion = cv2.GaussianBlur(gray_conversion, (5,5),0)
In[7]: cv2.imshow('input_image', blur_conversion)
In[8]: cv2.waitKey(0)
In[9]: cv2.destroyAllWindows()
The output is as follows:
Fig 5.3: Image after applying Gaussian blur
We smoothed the image and removed noise from it. In the next section, we will perform canny edge detection on the input image.