Merged Document With Conclusion Final
Merged Document With Conclusion Final
Theory:
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.
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
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.
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:
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)
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()
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)
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")
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