SlideShare a Scribd company logo
1 of 1
Download to read offline
AIR UNIVERSITY
Department of Electrical and Computer Engineering
Digital Image Processing Lab
Lab #7: Image Processing Techniques for Visual Enhancement
Student Name: Umar Mustafa
Roll No: 200365
Instructor: Engr. M. Farooq Khan
Lab Tasks
Apply different trasnformations.
Subplot with and without transformation.
1)Translation Type:(Geometric Transformation)
2)Scale (Type:Geometric Transformation)
3)Histogram Equalization (Type: Gray-Level Transformation)
4)Sharpening (Type: Filtering Operation)
5)Erosion (Type: Morphological Transformation)
6)Dilation (Type: Morphological Transformation)
7)Fast Fourier Transform (FFT) (Type: Fourier Transformation)
Conclusion
Transformations include operations that modify the spatial characteristics of an image, such as its size, position, orientation, and pixel values.
Common transformations include translation, scaling, rotation, shearing, and flipping, which alter the geometric properties of an image.
Other transformations, such as histogram equalization and sharpening, focus on enhancing image quality, improving contrast, and emphasizing important features.
Image transformations often involve applying specific algorithms or mathematical operations to achieve the desired effect.
Understanding the purpose and parameters of each transformation is essential to choose the appropriate technique for a specific task or application.
By applying transformations effectively, image processing techniques can be used for tasks like image restoration, feature extraction, object recognition, and more, leading to improved
visual quality and better analysis of images.
In [3]: import cv2
import numpy as np
import matplotlib.pyplot as plt
# Load the image
image = cv2.imread('F:/imagelab/droplets.jpg')
# Define the translation matrix
tx = 50 # translation in the x-axis
ty = 30 # translation in the y-axis
# We define the translation amounts tx and ty to specify how much we want to shift the image in the x-axis and y-axis
# Adjust these values according to your requirements.
translation_matrix = np.float32([[1, 0, tx], [0, 1, ty]])
# We create a 2x3 translation matrix using np.float32().
# Apply the translation transformation
translated_image = cv2.warpAffine(image, translation_matrix, (image.shape[1], image.shape[0]))
# We apply the translation transformation to the image using cv2.warpAffine().It takes the input image, translation matrix,
# and the desired output image size (image.shape[1], image.shape[0]) as parameters.The result is stored in the translated_image
# variable.
# Display the original and filtered images
plt.subplot(221)
plt.imshow(image)
plt.title('Original')
plt.subplot(222)
plt.imshow(translated_image)
plt.title('Translated Image')
plt.show()
In [4]: # Define the scaling factors
scale_x = 1.5 # scaling factor for the x-axis
scale_y = 1.5 # scaling factor for the y-axis
# We define the scaling factors scale_x and scale_y to specify how much we want to scale the image in the x-axis and y-axis,
# respectively. Adjust these values according to your requirements. A value greater than 1 enlarges the image, while a value
# less than 1 shrinks the image.
# Determine the new dimensions
new_width = int(image.shape[1] * scale_x)
new_height = int(image.shape[0] * scale_y)
new_dimensions = (new_width, new_height)
# The new width is obtained by multiplying the original width (image.shape[1]) with the scaling factor scale_x, and the new
# height is obtained by multiplying the original height (image.shape[0]) with the scaling factor scale_y. We convert the
# dimensions to integers using int() and store them in the new_width and new_height variables. The new dimensions are then
# stored as a tuple in the new_dimensions variable.
# Apply the scaling transformation
scaled_image = cv2.resize(image, new_dimensions)
# We apply the scaling transformation to the image using cv2.resize(). It takes the input image and the new dimensions as
# parameters. The function resizes the image to the specified dimensions and stores the result in the scaled_image variable.
# Display the original and scaled images
plt.subplot(221)
plt.imshow(image)
plt.title('Original')
plt.subplot(222)
plt.imshow(scaled_image)
plt.title('Scaled Image')
plt.show()
In [13]: # Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply histogram equalization
equalized_image = cv2.equalizeHist(gray_image)
# We apply histogram equalization to the grayscale image using the cv2.equalizeHist() function. The function takes the grayscale
# image as input and performs histogram equalization on it. The result is stored in the equalized_image variable.
# Display the original and scaled images
plt.subplot(221)
plt.imshow(gray_image)
plt.title('Original')
plt.subplot(222)
plt.imshow(equalized_image)
plt.title('Equalized_image')
plt.show()
In [16]: # Create the sharpening kernel
# We create a sharpening kernel using np.array(). The kernel is a 3x3 matrix that defines the sharpening filter.
kernel = np.array([[-1, -1, -1],
[-1, 9, -1],
[-1, -1, -1]])
# This kernel enhances edges and details by emphasizing high-frequency components and reducing the contribution of the
# surrounding pixels.
# Apply the sharpening transformation
sharpened_image = cv2.filter2D(image, -1, kernel)
# We apply the sharpening transformation to the image using cv2.filter2D(). It takes the input image, the desired depth of the
# destination image (-1 indicates the same depth as the input image), and the sharpening kernel as parameters. The function
# convolves the image with the kernel, accentuating edges and details, and stores the result in the sharpened_image variable.
# Display the original and sharpened images
plt.subplot(221)
plt.imshow(image)
plt.title('Original')
plt.subplot(222)
plt.imshow(sharpened_image)
plt.title('Sharpened Image')
plt.show()
In [17]: # Create a structuring element for erosion
kernel = np.ones((5, 5), np.uint8)
# We create a structuring element for erosion using np.ones(). The structuring element is a 5x5 matrix with all elements set to
# 1. This matrix defines the neighborhood around each pixel that is considered during the erosion operation. Adjust the size of
# the structuring element according to the desired effect.
# Apply erosion
eroded_image = cv2.erode(image, kernel, iterations=1)
# We apply the erosion operation to the image using cv2.erode(). It takes the input image, the structuring element (kernel), and
# the number of iterations as parameters. In this example, we perform erosion once (iterations=1). The function erodes the
# boundaries of the foreground objects, resulting in the reduction of object sizes.
# Display the original and eroded images
plt.subplot(221)
plt.imshow(image)
plt.title('Original')
plt.subplot(222)
plt.imshow(eroded_image)
plt.title('Eroded Image')
plt.show()
In [19]: # Create a structuring element for dilation
kernel = np.ones((5, 5), np.uint8)
# We create a structuring element for dilation using np.ones(). The structuring element is a 5x5 matrix with all elements set to
# 1. This matrix defines the neighborhood around each pixel that is considered during the dilation operation. Adjust the size of
# the structuring element according to the desired effect.
# Apply dilation
dilated_image = cv2.dilate(image, kernel, iterations=1)
# We apply the dilation operation to the image using cv2.dilate(). It takes the input image, the structuring element (kernel),
# and the number of iterations as parameters. In this example, we perform dilation once (iterations=1).The function expands
# the boundaries of the foreground objects, resulting in the enlargement of object sizes and the filling of holes or gaps.
# Display the original and dilated images
plt.subplot(221)
plt.imshow(image)
plt.title('Original')
plt.subplot(222)
plt.imshow(dilated_image)
plt.title('Dilated Image')
plt.show()
In [23]: # Perform FFT
fft_image = np.fft.fft2(image)
# We perform the Fast Fourier Transform (FFT) on the image using np.fft.fft2(). This function computes the 2-dimensional FFT of
# the input image, returning a complex-valued array. The result is stored in the fft_image variable.
# Shift the zero-frequency component to the center
shifted_fft_image = np.fft.fftshift(fft_image)
# We shift the zero-frequency component (DC component) of the FFT result to the center of the spectrum using np.fft.fftshift().
# This rearrangement is necessary to visualize the spectrum properly.
# Compute the magnitude spectrum
magnitude_spectrum = np.abs(shifted_fft_image)
magnitude_spectrum = np.log1p(magnitude_spectrum)
# Applied np.log1p() instead of np.log() to compute the logarithm with added 1.This helps avoid undefined values for zero inputs
# and handles the warning properly.
magnitude_spectrum = (magnitude_spectrum - np.min(magnitude_spectrum)) / np.ptp(magnitude_spectrum)
# Normalized the magnitude_spectrum array using (magnitude_spectrum - np.min(magnitude_spectrum)) / np.ptp(magnitude_spectrum)
# to scale the values to the range [0, 1].
# Display the original image and its magnitude spectrum
plt.subplot(121)
plt.imshow(image, cmap='gray')
plt.title('Original Image')
plt.xticks([]), plt.yticks([]) # plt.xticks([]) and plt.yticks([]) remove the tick labels
plt.subplot(122)
plt.imshow(magnitude_spectrum, cmap='gray')
plt.title('Magnitude Spectrum')
plt.xticks([]), plt.yticks([]) # plt.xticks([]) and plt.yticks([]) remove the tick labels,
plt.show()

More Related Content

Similar to Image Processing Lab Report: Visual Enhancement Techniques

Matlab intro
Matlab introMatlab intro
Matlab introfvijayami
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_projectManish Jauhari
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfUmarMustafa13
 
Intensity Transformation and Spatial filtering
Intensity Transformation and Spatial filteringIntensity Transformation and Spatial filtering
Intensity Transformation and Spatial filteringShajun Nisha
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfssuserb4d806
 
Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)Moe Moe Myint
 
Basics of image processing using MATLAB
Basics of image processing using MATLABBasics of image processing using MATLAB
Basics of image processing using MATLABMohsin Siddique
 
Image Classification using Deep Learning
Image Classification using Deep LearningImage Classification using Deep Learning
Image Classification using Deep LearningIRJET Journal
 
could you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdfcould you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdfmurtuzadahadwala3
 
DIP-Enhancement-Spatial.pptx
DIP-Enhancement-Spatial.pptxDIP-Enhancement-Spatial.pptx
DIP-Enhancement-Spatial.pptxNidhiSharma764884
 
Image enhancement ppt nal2
Image enhancement ppt nal2Image enhancement ppt nal2
Image enhancement ppt nal2Surabhi Ks
 
03 image transformations_i
03 image transformations_i03 image transformations_i
03 image transformations_iankit_ppt
 
Scene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesScene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesBryan Duggan
 

Similar to Image Processing Lab Report: Visual Enhancement Techniques (20)

Matlab intro
Matlab introMatlab intro
Matlab intro
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_project
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdf
 
Intensity Transformation and Spatial filtering
Intensity Transformation and Spatial filteringIntensity Transformation and Spatial filtering
Intensity Transformation and Spatial filtering
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
 
CNN_INTRO.pptx
CNN_INTRO.pptxCNN_INTRO.pptx
CNN_INTRO.pptx
 
Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)
 
Basics of image processing using MATLAB
Basics of image processing using MATLABBasics of image processing using MATLAB
Basics of image processing using MATLAB
 
Image Classification using Deep Learning
Image Classification using Deep LearningImage Classification using Deep Learning
Image Classification using Deep Learning
 
Topic 1_PPT.pptx
Topic 1_PPT.pptxTopic 1_PPT.pptx
Topic 1_PPT.pptx
 
could you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdfcould you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdf
 
Ijcatr04051016
Ijcatr04051016Ijcatr04051016
Ijcatr04051016
 
Report
ReportReport
Report
 
DIP-Enhancement-Spatial.pptx
DIP-Enhancement-Spatial.pptxDIP-Enhancement-Spatial.pptx
DIP-Enhancement-Spatial.pptx
 
Bai 1
Bai 1Bai 1
Bai 1
 
Image enhancement ppt nal2
Image enhancement ppt nal2Image enhancement ppt nal2
Image enhancement ppt nal2
 
Medial axis transformation based skeletonzation of image patterns using image...
Medial axis transformation based skeletonzation of image patterns using image...Medial axis transformation based skeletonzation of image patterns using image...
Medial axis transformation based skeletonzation of image patterns using image...
 
03 image transformations_i
03 image transformations_i03 image transformations_i
03 image transformations_i
 
Dip Morphological
Dip MorphologicalDip Morphological
Dip Morphological
 
Scene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesScene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game Engines
 

More from UmarMustafa13

CEA Technical English.pptx
CEA Technical English.pptxCEA Technical English.pptx
CEA Technical English.pptxUmarMustafa13
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfUmarMustafa13
 
CE344L-200365-Lab4.pdf
CE344L-200365-Lab4.pdfCE344L-200365-Lab4.pdf
CE344L-200365-Lab4.pdfUmarMustafa13
 
CE344L-200365-Lab3.pdf
CE344L-200365-Lab3.pdfCE344L-200365-Lab3.pdf
CE344L-200365-Lab3.pdfUmarMustafa13
 
CE344L-200365-Lab8.pdf
CE344L-200365-Lab8.pdfCE344L-200365-Lab8.pdf
CE344L-200365-Lab8.pdfUmarMustafa13
 

More from UmarMustafa13 (6)

CEA Technical English.pptx
CEA Technical English.pptxCEA Technical English.pptx
CEA Technical English.pptx
 
CEA-3-Activity.pptx
CEA-3-Activity.pptxCEA-3-Activity.pptx
CEA-3-Activity.pptx
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
CE344L-200365-Lab4.pdf
CE344L-200365-Lab4.pdfCE344L-200365-Lab4.pdf
CE344L-200365-Lab4.pdf
 
CE344L-200365-Lab3.pdf
CE344L-200365-Lab3.pdfCE344L-200365-Lab3.pdf
CE344L-200365-Lab3.pdf
 
CE344L-200365-Lab8.pdf
CE344L-200365-Lab8.pdfCE344L-200365-Lab8.pdf
CE344L-200365-Lab8.pdf
 

Recently uploaded

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 

Recently uploaded (20)

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 

Image Processing Lab Report: Visual Enhancement Techniques

  • 1. AIR UNIVERSITY Department of Electrical and Computer Engineering Digital Image Processing Lab Lab #7: Image Processing Techniques for Visual Enhancement Student Name: Umar Mustafa Roll No: 200365 Instructor: Engr. M. Farooq Khan Lab Tasks Apply different trasnformations. Subplot with and without transformation. 1)Translation Type:(Geometric Transformation) 2)Scale (Type:Geometric Transformation) 3)Histogram Equalization (Type: Gray-Level Transformation) 4)Sharpening (Type: Filtering Operation) 5)Erosion (Type: Morphological Transformation) 6)Dilation (Type: Morphological Transformation) 7)Fast Fourier Transform (FFT) (Type: Fourier Transformation) Conclusion Transformations include operations that modify the spatial characteristics of an image, such as its size, position, orientation, and pixel values. Common transformations include translation, scaling, rotation, shearing, and flipping, which alter the geometric properties of an image. Other transformations, such as histogram equalization and sharpening, focus on enhancing image quality, improving contrast, and emphasizing important features. Image transformations often involve applying specific algorithms or mathematical operations to achieve the desired effect. Understanding the purpose and parameters of each transformation is essential to choose the appropriate technique for a specific task or application. By applying transformations effectively, image processing techniques can be used for tasks like image restoration, feature extraction, object recognition, and more, leading to improved visual quality and better analysis of images. In [3]: import cv2 import numpy as np import matplotlib.pyplot as plt # Load the image image = cv2.imread('F:/imagelab/droplets.jpg') # Define the translation matrix tx = 50 # translation in the x-axis ty = 30 # translation in the y-axis # We define the translation amounts tx and ty to specify how much we want to shift the image in the x-axis and y-axis # Adjust these values according to your requirements. translation_matrix = np.float32([[1, 0, tx], [0, 1, ty]]) # We create a 2x3 translation matrix using np.float32(). # Apply the translation transformation translated_image = cv2.warpAffine(image, translation_matrix, (image.shape[1], image.shape[0])) # We apply the translation transformation to the image using cv2.warpAffine().It takes the input image, translation matrix, # and the desired output image size (image.shape[1], image.shape[0]) as parameters.The result is stored in the translated_image # variable. # Display the original and filtered images plt.subplot(221) plt.imshow(image) plt.title('Original') plt.subplot(222) plt.imshow(translated_image) plt.title('Translated Image') plt.show() In [4]: # Define the scaling factors scale_x = 1.5 # scaling factor for the x-axis scale_y = 1.5 # scaling factor for the y-axis # We define the scaling factors scale_x and scale_y to specify how much we want to scale the image in the x-axis and y-axis, # respectively. Adjust these values according to your requirements. A value greater than 1 enlarges the image, while a value # less than 1 shrinks the image. # Determine the new dimensions new_width = int(image.shape[1] * scale_x) new_height = int(image.shape[0] * scale_y) new_dimensions = (new_width, new_height) # The new width is obtained by multiplying the original width (image.shape[1]) with the scaling factor scale_x, and the new # height is obtained by multiplying the original height (image.shape[0]) with the scaling factor scale_y. We convert the # dimensions to integers using int() and store them in the new_width and new_height variables. The new dimensions are then # stored as a tuple in the new_dimensions variable. # Apply the scaling transformation scaled_image = cv2.resize(image, new_dimensions) # We apply the scaling transformation to the image using cv2.resize(). It takes the input image and the new dimensions as # parameters. The function resizes the image to the specified dimensions and stores the result in the scaled_image variable. # Display the original and scaled images plt.subplot(221) plt.imshow(image) plt.title('Original') plt.subplot(222) plt.imshow(scaled_image) plt.title('Scaled Image') plt.show() In [13]: # Convert the image to grayscale gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Apply histogram equalization equalized_image = cv2.equalizeHist(gray_image) # We apply histogram equalization to the grayscale image using the cv2.equalizeHist() function. The function takes the grayscale # image as input and performs histogram equalization on it. The result is stored in the equalized_image variable. # Display the original and scaled images plt.subplot(221) plt.imshow(gray_image) plt.title('Original') plt.subplot(222) plt.imshow(equalized_image) plt.title('Equalized_image') plt.show() In [16]: # Create the sharpening kernel # We create a sharpening kernel using np.array(). The kernel is a 3x3 matrix that defines the sharpening filter. kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]]) # This kernel enhances edges and details by emphasizing high-frequency components and reducing the contribution of the # surrounding pixels. # Apply the sharpening transformation sharpened_image = cv2.filter2D(image, -1, kernel) # We apply the sharpening transformation to the image using cv2.filter2D(). It takes the input image, the desired depth of the # destination image (-1 indicates the same depth as the input image), and the sharpening kernel as parameters. The function # convolves the image with the kernel, accentuating edges and details, and stores the result in the sharpened_image variable. # Display the original and sharpened images plt.subplot(221) plt.imshow(image) plt.title('Original') plt.subplot(222) plt.imshow(sharpened_image) plt.title('Sharpened Image') plt.show() In [17]: # Create a structuring element for erosion kernel = np.ones((5, 5), np.uint8) # We create a structuring element for erosion using np.ones(). The structuring element is a 5x5 matrix with all elements set to # 1. This matrix defines the neighborhood around each pixel that is considered during the erosion operation. Adjust the size of # the structuring element according to the desired effect. # Apply erosion eroded_image = cv2.erode(image, kernel, iterations=1) # We apply the erosion operation to the image using cv2.erode(). It takes the input image, the structuring element (kernel), and # the number of iterations as parameters. In this example, we perform erosion once (iterations=1). The function erodes the # boundaries of the foreground objects, resulting in the reduction of object sizes. # Display the original and eroded images plt.subplot(221) plt.imshow(image) plt.title('Original') plt.subplot(222) plt.imshow(eroded_image) plt.title('Eroded Image') plt.show() In [19]: # Create a structuring element for dilation kernel = np.ones((5, 5), np.uint8) # We create a structuring element for dilation using np.ones(). The structuring element is a 5x5 matrix with all elements set to # 1. This matrix defines the neighborhood around each pixel that is considered during the dilation operation. Adjust the size of # the structuring element according to the desired effect. # Apply dilation dilated_image = cv2.dilate(image, kernel, iterations=1) # We apply the dilation operation to the image using cv2.dilate(). It takes the input image, the structuring element (kernel), # and the number of iterations as parameters. In this example, we perform dilation once (iterations=1).The function expands # the boundaries of the foreground objects, resulting in the enlargement of object sizes and the filling of holes or gaps. # Display the original and dilated images plt.subplot(221) plt.imshow(image) plt.title('Original') plt.subplot(222) plt.imshow(dilated_image) plt.title('Dilated Image') plt.show() In [23]: # Perform FFT fft_image = np.fft.fft2(image) # We perform the Fast Fourier Transform (FFT) on the image using np.fft.fft2(). This function computes the 2-dimensional FFT of # the input image, returning a complex-valued array. The result is stored in the fft_image variable. # Shift the zero-frequency component to the center shifted_fft_image = np.fft.fftshift(fft_image) # We shift the zero-frequency component (DC component) of the FFT result to the center of the spectrum using np.fft.fftshift(). # This rearrangement is necessary to visualize the spectrum properly. # Compute the magnitude spectrum magnitude_spectrum = np.abs(shifted_fft_image) magnitude_spectrum = np.log1p(magnitude_spectrum) # Applied np.log1p() instead of np.log() to compute the logarithm with added 1.This helps avoid undefined values for zero inputs # and handles the warning properly. magnitude_spectrum = (magnitude_spectrum - np.min(magnitude_spectrum)) / np.ptp(magnitude_spectrum) # Normalized the magnitude_spectrum array using (magnitude_spectrum - np.min(magnitude_spectrum)) / np.ptp(magnitude_spectrum) # to scale the values to the range [0, 1]. # Display the original image and its magnitude spectrum plt.subplot(121) plt.imshow(image, cmap='gray') plt.title('Original Image') plt.xticks([]), plt.yticks([]) # plt.xticks([]) and plt.yticks([]) remove the tick labels plt.subplot(122) plt.imshow(magnitude_spectrum, cmap='gray') plt.title('Magnitude Spectrum') plt.xticks([]), plt.yticks([]) # plt.xticks([]) and plt.yticks([]) remove the tick labels, plt.show()