Search Creators CG LAB Program-10

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

21CSL66 | COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY|

Subject Code:21CSL66

Subject: COMPUTER GRAPHICS AND IMAGE PROCESSING


LABORATORY

Program-10

10. Write a program to blur and smoothing an image.

Program

import cv2

# Load the image

image = cv2.imread('image/atc.jpg')

# Gaussian Blur

gaussian_blur = cv2.GaussianBlur(image, (5, 5), 0)

# Median Blur

median_blur = cv2.medianBlur(image, 5)

# Bilateral Filter

bilateral_filter = cv2.bilateralFilter(image, 9, 75, 75)

# Display the original and processed images

cv2.imshow('Original Image', image)

Search Creators…. Page 1


21CSL66 | COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY|

cv2.imshow('Gaussian Blur', gaussian_blur)

cv2.imshow('Median Blur', median_blur)

cv2.imshow('Bilateral Filter', bilateral_filter)

# Wait for a key press to close the windows

cv2.waitKey(0)

cv2.destroyAllWindows()

Output

Search Creators…. Page 2


21CSL66 | COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY|

Search Creators…. Page 3


21CSL66 | COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY|

Explanation

1. The cv2 library is imported from OpenCV.


2. The image is loaded using cv2.imread('image/atc.jpg'). Make sure to replace
'image/atc.jpg' with the correct path to your image file.
3. Three different types of blurring/smoothing filters are applied to the image:
4. Gaussian Blur: gaussian_blur = cv2.GaussianBlur(image, (5, 5), 0) applies a
Gaussian blur filter to the image. The parameters (5, 5) specify the size of the
Gaussian kernel, and 0 is the standard deviation value in the X and Y
directions (which is automatically calculated from the kernel size).
5. Median Blur: median_blur = cv2.medianBlur(image, 5) applies a median blur
filter to the image. The parameter 5 specifies the size of the median filter
kernel.
6. Bilateral Filter: bilateral_filter = cv2.bilateralFilter(image, 9, 75, 75) applies
a bilateral filter to the image. The parameters 9, 75, and 75 represent the
diameter of the pixel neighborhood, the filter sigma in the color space, and the
filter sigma in the coordinate space, respectively.
7. The original image and the filtered images are displayed using cv2.imshow().
8. The script waits for a key press (cv2.waitKey(0)) before closing the windows.
9. Finally, all windows are closed using cv2.destroyAllWindows().

Search Creators…. Page 4

You might also like