0% found this document useful (0 votes)
11 views10 pages

Merged Document With Conclusion Final

nol

Uploaded by

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

Merged Document With Conclusion Final

nol

Uploaded by

Paritosh Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Department of Computer Science and Engineering (Data Science)

Image Processing and Computer Vision I (DJ19DSL603)


Lab 5: Image Enhancement in Spatial Domain using Neighbourhood Processing
Techniques

Aim: To perform image enhancement in spatial domain using neighbourhood


processing techniques: Basic High Pass and High Boost filtering

Theory:

1. Basic High Pass:

The principal objective of high pass (sharpening) filter is to highlight fine detail
in an image or to enhance detail that has been blurred, either in error or as a natural
effect of a particular method of image acquisition. Uses of image sharpening vary
and include applications ranging from electronic printing and medical imaging to
industrial inspection and autonomous target detection in military systems.

The shape of the impulse response needed to have a high pass (sharpening) spatial
filter indicates that the filter should have positive coefficients in the outer
periphery. For a 3 x 3 mask, choosing a positive value in the centre location with
negative coefficients in the rest of the mask meets this condition. Thus when the
mask is over an area of constant or slowly varying gray level, the output of the
mask is zero or very small. This result is consistent with what is expected from
the corresponding frequency domain filter.

fig 1. A high pass filter mask

2. High Boost Filter:

The goal of high boost filtering is to enhance the high frequency


information without completely eliminating the background of the image.

We know that:
(High-pass filtered image)=(Original image)-(Low-pass filtered image)

We define:
Department of Computer Science and Engineering (Data Science)
Image Processing and Computer Vision I (DJ19DSL603)
Lab 5: Image Enhancement in Spatial Domain using Neighbourhood Processing
Techniques

(High boost filtered image) = 𝐴 × (Original image) - (Low-pass filtered image)


(High boost) = (𝐴−1) × (Original) + (Original) - (Low-pass)
(High boost) = (𝐴−1) × (Original) + (High-pass)

Note:
i. when 𝐴>1, part of the original is added back to the high-pass filtered
version of the image in order to partly restore the lowfrequency
components that would have been eliminated with standardhigh-
pass filtering.
ii. Typical values for 𝐴 are values slightly higher than 1, as for example
1.15, 1.2, etc.

The resulting image looks similar to the original image with some edge
enhancement.

The spatial mask that implements the high boost filtering algorithm is shown
below.

fig 2. High boost filter mask

The resulting image depends on the choice of A.

Lab Assignments to complete in this session


Department of Computer Science and Engineering (Data Science)
Image Processing and Computer Vision I (DJ19DSL603)
Lab 5: Image Enhancement in Spatial Domain using Neighbourhood Processing
Techniques

Problem Statement: Develop a Python program utilizing the OpenCV library to enhace
the images in spatial domain using neighbourhood processing with sharpening operators
(High pass filtering and High boost filtering). The program should address the following
tasks:

1. Read any low contrast image from COVID 19 Image Dataset.


Dataset Link: Covid-19 Image Dataset
2. Display the before & after image(s) used in every task below.
3. Apply basic high pass filter and compare the before and after result.
4. Apply basic high boost filter and compare the before and after result.

The solution to the operations performed must be produced by scratch coding without
the use of built in OpenCV methods.
10/2/24, 11:48 PM exp_6.ipynb - Colab

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image

def read_image(image_path):
img = Image.open(image_path).convert('L')
return np.array(img)

def read_image_color(image_path):
img = Image.open(image_path).convert('RGB')
return np.array(img)

def display_images(original, filtered, title1, title2):


plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.title(title1)
if original.ndim == 2:
plt.imshow(original, cmap='gray')
else:
plt.imshow(original)
plt.axis('off')

plt.subplot(1, 2, 2)
plt.title(title2)
if filtered.ndim == 2:
plt.imshow(filtered, cmap='gray')
else:
plt.imshow(filtered)
plt.axis('off')
plt.show()

def apply_filter(image, kernel):


kernel_size = kernel.shape[0]
pad = kernel_size // 2

if image.ndim == 3:
padded_image = np.pad(image, ((pad, pad), (pad, pad), (0, 0)), mode='constant')
filtered_image = np.zeros_like(image)

for i in range(image.shape[0]):
for j in range(image.shape[1]):
region = padded_image[i:i + kernel_size, j:j + kernel_size]
for channel in range(image.shape[2]):
filtered_image[i, j, channel] = np.sum(region[:, :, channel] * kernel)

else:
padded_image = np.pad(image, pad, mode='constant')
filtered_image = np.zeros_like(image)

for i in range(image.shape[0]):
for j in range(image.shape[1]):
region = padded_image[i:i + kernel_size, j:j + kernel_size]
filtered_image[i, j] = np.sum(region * kernel)

return filtered_image

def high_pass_filter(image):
kernel = np.array([[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]])
return apply_filter(image, kernel)

def low_pass_filter(image):
kernel = np.array([[1/16, 2/16, 1/16],
[2/16, 4/16, 2/16],
[1/16, 2/16, 1/16]])
return apply_filter(image, kernel)

def high_boost_filter(image, A):


low_passed = low_pass_filter(image)
high_passed = high_pass_filter(image)
boosted = (A - 1) * image + high_passed

https://colab.research.google.com/drive/1EXPNL5DiakudqM1QuPXnWpZJRTtL57BL#scrollTo=PbpUmr54alEm&printMode=true 1/5
10/2/24, 11:48 PM exp_6.ipynb - Colab
boosted = np.clip(boosted, 0, 255)
return boosted.astype(np.uint8)

image_path = '/content/Low-contrast-detailed-image-of-a-religious-building.png'
original_image = read_image(image_path)

high_passed_image = high_pass_filter(original_image)
display_images(original_image, high_passed_image, "Original Image", "High Pass Filtered Image")

A = 1
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

A = 0.5
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

https://colab.research.google.com/drive/1EXPNL5DiakudqM1QuPXnWpZJRTtL57BL#scrollTo=PbpUmr54alEm&printMode=true 2/5
10/2/24, 11:48 PM exp_6.ipynb - Colab

A = 1.5
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

image_path = '/content/photo-1472820555436-84b6cad88e04.jpeg'
original_image = read_image(image_path)

high_passed_image = high_pass_filter(original_image)
display_images(original_image, high_passed_image, "Original Image", "High Pass Filtered Image")

A = 1
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

https://colab.research.google.com/drive/1EXPNL5DiakudqM1QuPXnWpZJRTtL57BL#scrollTo=PbpUmr54alEm&printMode=true 3/5
10/2/24, 11:48 PM exp_6.ipynb - Colab

A = 0.5
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

Start coding or generate with AI.

A = 1.5
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

image_path = '/content/csm_picture_8_1b8bcd4956.jpg'
original_image = read_image(image_path)

high_passed_image = high_pass_filter(original_image)
display_images(original_image, high_passed_image, "Original Image", "High Pass Filtered Image")

https://colab.research.google.com/drive/1EXPNL5DiakudqM1QuPXnWpZJRTtL57BL#scrollTo=PbpUmr54alEm&printMode=true 4/5
10/2/24, 11:48 PM exp_6.ipynb - Colab

A = 1
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

A = 0.5
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

A = 1.5
high_boosted_image = high_boost_filter(original_image, A)
display_images(original_image, high_boosted_image, "Original Image", "High Boost Filtered Image")

https://colab.research.google.com/drive/1EXPNL5DiakudqM1QuPXnWpZJRTtL57BL#scrollTo=PbpUmr54alEm&printMode=true 5/5
Conclusion:
In this experiment, we explored two powerful image enhancement techniques:
High Pass Filtering and High Boost Filtering.
High Pass Filtering was effective in sharpening images by enhancing edges and fine details,
making it a useful tool for applications such as medical imaging and industrial inspection.
High Boost Filtering allowed for selective enhancement of high-frequency components,
providing flexibility in controlling the degree of enhancement by adjusting the parameter 'A'.
Both techniques demonstrated their effectiveness in improving image quality,
and their applicability can be extended to various real-world scenarios requiring enhanced visual

You might also like