0% found this document useful (0 votes)
2 views11 pages

Week 11 Programs

The document outlines various image enhancement techniques using Python, specifically through Google Colab and offline software. It includes programs for spatial filtering, averaging, Gaussian blur, median blur, and bilateral blur, with visual outputs for each technique. Each section provides code snippets and descriptions for applying these filters to enhance images.

Uploaded by

bantudeepika07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Week 11 Programs

The document outlines various image enhancement techniques using Python, specifically through Google Colab and offline software. It includes programs for spatial filtering, averaging, Gaussian blur, median blur, and bilateral blur, with visual outputs for each technique. Each section provides code snippets and descriptions for applying these filters to enhance images.

Uploaded by

bantudeepika07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Week 11 Programs

Exercises on Image Enhancement


11.1 Spatial Filtering and its Types
Program for Google Colab:
import cv2
import numpy as np
import [Link] as plt
from [Link] import files

uploaded = [Link]()
image_path = list([Link]())[0]

img = [Link](image_path)
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)

low_pass_kernel = [Link]((3,3), np.float32) / 9


low_pass = cv2.filter2D(img_rgb, -1, low_pass_kernel)

high_pass_kernel = [Link]([[0,-1,0], [-1,5,-1], [0,-1,0]])


high_pass = cv2.filter2D(img_rgb, -1, high_pass_kernel)
laplacian = [Link](img_rgb, cv2.CV_64F)
laplacian = np.uint8([Link](laplacian))

[Link](figsize=(15,10))
[Link](2,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](2,2,2)
[Link](low_pass)
[Link]("Low Pass Filter (Smoothing)")
[Link]("off")

[Link](2,2,3)
[Link](high_pass)
[Link]("High Pass Filter (Sharpening)")
[Link]("off")
[Link](2,2,4)
[Link](laplacian)
[Link]("Laplacian Edge Detection")
[Link]("off")
plt.tight_layout()
[Link]()

Program for Offline Python Software:

import cv2
import numpy as np
import [Link] as plt

img = [Link]("[Link]")
if img is None:
print("Error: Image not found. Check the file path.")
exit()
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)
low_pass_kernel = [Link]((3,3), np.float32)/9
low_pass = cv2.filter2D(img_rgb, -1, low_pass_kernel)
high_pass_kernel = [Link]([[0,-1,0], [-1,5,-1], [0,-1,0]])
high_pass = cv2.filter2D(img_rgb, -1, high_pass_kernel)

laplacian = [Link](img_rgb, cv2.CV_64F)


laplacian = np.uint8([Link](laplacian))

[Link](figsize=(12,8))
[Link](2,2,1)
[Link](img_rgb)
[Link]("Original Image")
[Link]("off")
[Link](2,2,2)
[Link](low_pass)
[Link]("Low Pass Filter")
[Link]("off")
[Link](2,2,3)
[Link](high_pass)
[Link]("High Pass Filter")
[Link]("off")
[Link](2,2,4)
[Link](laplacian)
[Link]("Laplacian Filter")
[Link]("off")
plt.tight_layout()
[Link]()

Output

Flowchart
11.2 Averaging an Image
Program for Google Colab:
import cv2
import numpy as np
import [Link] as plt
from [Link] import files
uploaded = [Link]()
image_path = list([Link]())[0]

img = [Link](image_path)
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)

averaged_3x3 = [Link](img_rgb, (3,3))


[Link](figsize=(18,8))
[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](averaged_3x3)
[Link]("Averaging 3x3")
[Link]("off")
plt.tight_layout()
[Link]()

Program for Offline Python Software:

import cv2
import numpy as np
import [Link] as plt

img = [Link]("[Link]")
if img is None:
print("Error: Image not found. Check the file path.")
exit()
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)
average_3x3 = [Link](img_rgb, (3,3))
[Link](figsize=(12,6))
[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](average_3x3)
[Link]("Averaging 3x3")
[Link]("off")
plt.tight_layout()
[Link]()

OUTPUT

Flowchart
11.3 Gaussian Blur
Program for Google Colab:

import cv2
import numpy as np
import [Link] as plt
from [Link] import files
uploaded = [Link]()
image_path = list([Link]())[0]

img = [Link](image_path)
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)

gaussian_3x3 = [Link](img_rgb, (3,3), 0)


[Link](figsize=(18,8))

[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](gaussian_3x3)
[Link]("Gaussian Blur 3x3")
[Link]("off")
plt.tight_layout()
[Link]()

Program for Offline Python Software:

import cv2
import numpy as np
import [Link] as plt
img = [Link]("[Link]")

if img is None:
print("Error: Image not found. Check the file path.")
exit()
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)
gaussian_3x3 = [Link](img_rgb, (3,3), 0)
[Link](figsize=(15,6))
[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](gaussian_3x3)
[Link]("Gaussian 3x3")
[Link]("off")
plt.tight_layout()
[Link]()

Output

Flowchart
11.4 Median blur
Program for Google Colab:

import cv2
import numpy as np
import [Link] as plt
from [Link] import files
uploaded = [Link]()
image_path = list([Link]())[0]

img = [Link](image_path)
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)

median_3 = [Link](img_rgb, 3)
[Link](figsize=(18,8))

[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](median_3)
[Link]("Median Blur 3x3")
[Link]("off")
plt.tight_layout()
[Link]()

Program for Offline Python Software:

import cv2
import numpy as np
import [Link] as plt
img = [Link]("[Link]")
if img is None:
print("Error: Image not found. Check the file path.")
exit()

img_rgb = [Link](img, cv2.COLOR_BGR2RGB)


median_3 = [Link](img_rgb, 3)
[Link](figsize=(15,6))
[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](median_3)
[Link]("Median 3x3")
[Link]("off")
plt.tight_layout()
[Link]()

Output

Flowchart
11.5 Bilateral blur
Program for Google Colab:

import cv2
import numpy as np
import [Link] as plt
from [Link] import files

uploaded = [Link]()
image_path = list([Link]())[0]

img = [Link](image_path)
img_rgb = [Link](img, cv2.COLOR_BGR2RGB)

bilateral_3 = [Link](img_rgb, 3, 75, 75)


[Link](figsize=(18,8))
[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](bilateral_3)
[Link]("Bilateral Filter d=3")
[Link]("off")
plt.tight_layout()
[Link]()

Program for Offline Python Software:

import cv2
import numpy as np
import [Link] as plt
img = [Link]("[Link]")
if img is None:
print("Error: Image not found. Check the file path.")
exit()

img_rgb = [Link](img, cv2.COLOR_BGR2RGB)


bilateral_3 = [Link](img_rgb, 3, 75, 75)
[Link](figsize=(15,6))
[Link](1,2,1)
[Link](img_rgb)
[Link]("Original Colour Image")
[Link]("off")
[Link](1,2,2)
[Link](bilateral_3)
[Link]("Bilateral d=3")
[Link]("off")
plt.tight_layout()
[Link]()

OUTPUT

FLOWCHART

You might also like