0% found this document useful (0 votes)
9 views8 pages

64 - MVL - Exp 2

The document outlines an experiment conducted by Siddique Ahmed Fazeel at St. John College of Engineering and Management, focusing on image processing using OpenCV 3. It covers converting between different color spaces, the Fourier Transform, and the implementation of high pass and low pass filters. The experiment includes theoretical explanations and practical programming examples demonstrating these concepts.

Uploaded by

220ahmed2022
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)
9 views8 pages

64 - MVL - Exp 2

The document outlines an experiment conducted by Siddique Ahmed Fazeel at St. John College of Engineering and Management, focusing on image processing using OpenCV 3. It covers converting between different color spaces, the Fourier Transform, and the implementation of high pass and low pass filters. The experiment includes theoretical explanations and practical programming examples demonstrating these concepts.

Uploaded by

220ahmed2022
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
You are on page 1/ 8

Aldel Education Trust’s

St. John College of Engineering and Management, Palghar


(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
Name-Siddique Ahmed Fazeel
Class-BE_COMPS_64
Experiment 02
Title : Processing Images with OpenCV 3
Aim : Converting between different color spaces,The Fourier Transform, High pass
filter, Low pass filter.
Theory :
Converting between different color spaces
The various color spaces exist because they present color information in ways that make
certain calculations more convenient or because they provide a way to identify colors that is
more intuitive. For example, the RGB color space defines a color as the percentages of red,
green, and blue hues mixed together. There are literally hundreds of methods in OpenCV that
pertain to the conversion of color spaces. In general, three color spaces are prevalent in
modern day computer vision: gray, BGR, and Hue, Saturation, Value (HSV).
● Gray is a color space that effectively eliminates color information
translating to shades of gray: this color space is extremely useful for
intermediate processing, such as face detection.
● BGR is the blue-green-red color space, in which each pixel is a three-element
array, each value representing the blue, green, and red colors: web developers
would be familiar with a similar definition of colors, except the order of colors is
RGB.
● In HSV, hue is a color tone, saturation is the intensity of a color, and value
represents its darkness (or brightness at the opposite end of the spectrum).

The Fourier Transform


Fourier Transform is used to analyze the frequency characteristics of various filters. For
images, 2D Discrete Fourier Transform (DFT) is used to find the frequency domain. A fast
algorithm called Fast Fourier Transform (FFT) is used for calculation of DFT. Performance of
DFT calculation is better for some array size. It is fastest when array size is power of two. The
arrays whose size is a product of 2’s, 3’s, and 5’s are also processed quite efficiently. So if you
are worried about the performance of your code, you can modify the size of the array to any
optimal size (by padding zeros).
OpenCV provides a function, cv.getOptimalDFTSize() ,cv.getOptimalDFTSize (vecsize),
cv.copyMakeBorder (src, dst, top, bottom, left, right, borderType, value = new cv.Scalar()),
Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
cv.magnitude (x, y, magnitude)
Parameters
x floating-point array of x-coordinates of the vectors.

y floating-point array of y-coordinates of the vectors; it must have the same


x.

magnitude output array of the same size and type as


x. cv.split (m, mv)
Parameters
m input multi-channel array.

mv output vector of arrays; the arrays themselves are reallocated, if needed

cv.merge (mv,
dst) Parameters
mv input vector of matrices to be merged; all the matrices in mv must have the same
the same depth.

dst output array of the same size and the same depth as mv[0]; The number of chann
be the total number of channels in the matrix array.

High pass filter


A high pass filter (HPF) is a filter that examines a region of an image and boosts the intensity
of certain pixels based on the difference in the intensity with the surrounding pixels.
Take, for example, the following kernel:
[[0, -0.25, 0],
[-0.25, 1, -0.25],
[0, -0.25, 0]]
After calculating the sum of differences of the intensities of the central pixel compared to all
the immediate neighbors, the intensity of the central pixel will be boosted (or not) if a high
level of changes are found. In other words, if a pixel stands out from the surrounding pixels, it
will get boosted. This is particularly effective in edge detection, where a common form of HPF
called a high boost filter is used.

Low pass filter.


Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
If an HPF boosts the intensity of a pixel, given its difference with its neighbors, a low pass filter (LPF)
will smoothen the pixel if the difference with the surrounding pixels is lower than a certain threshold.
This is used in denoising and blurring. For example, one of the most popular blurring/smoothening
filters, the Gaussian blur, is a low pass filter that attenuates the intensity of high frequency signals.
Both high pass and low pass filters use a property called radius, which extends the area of the
neighbors involved in the filter calculation.

Program :
Converting between different color spaces
import cv2
import numpy as np
path = r'C:\Users\Admin\Desktop\saturn.jfif'
img =
cv2.imread(path,cv2.IMREAD_COLOR)
gray =
cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow('BGR',img)
cv2.imshow('Gray',gray)
cv2.waitKey(0)
cv2.destroyAllWindows(
)

The Fourier Transform


import cv2
import numpy as np
img = cv2.imread('ear.png',cv2.IMREAD_GRAYSCALE)
f=np.fft.fft2(img)
magnitude_spectrum = 20*np.log(np.abs(f))
magnitude_spectrum =
np.asarray(magnitude_spectrum,dtype=np.uint8)
cv2.imshow("magnitude spectrum",magnitude_spectrum)
cv2.imshow("Image",img)
cv2.waitKey(0)
cv2.destroyAllWindows(
)

High pass filter


import cv2
img = cv2.imread("ear2.jpg")
img = cv2.resize(img, (680,
520),interpolation=cv2.INTER_CUBIC) # subtract the original
image with the blurred image
# after subtracting add 127 to the total result
Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
hpf = img - cv2.GaussianBlur(img, (21, 21), 3)+127
# display both original image and filtered image
cv2.imshow("Original", img)
Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
cv2.imshow("High Passed Filter",
hpf) cv2.waitKey(0)
cv2.destroyAllWindows()

Low pass filter.


import cv2
import numpy as np
import matplotlib.pyplot as plt

Img=cv2.imread('ear2.jpg',
0) f= np.fft.fft2(img)
fshift =
np.fft.fftshift(f) rows,
cols = img.shape
crow,ccol = int(rows/2), int(cols/2)
fshift[crow-30:crow+30, ccol-30:ccol+30] =
0 ishift = np.fft.ifftshift(fshift)
iimg =
np.fft.ifft2(ishift) iimg
= np.abs(img)
plt.subplot(121),plt.imshow(img, cmap =
'gray') plt.title('original'),plt.axis('off')
plt.subplot(122), plt.imshow(iimg, cmap =
'gray') plt.title('img'),plt.axis('off')
plt.show()
Output :
Converting between different color spaces
Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
The Fourier Transform

High pass filter


Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING
Aldel Education Trust’s
St. John College of Engineering and Management, Palghar
(A Christian Religious Minority Institution)
Approved by AICTE and DTE, Affiliated to University of Mumbai/MSBTE
St. John Technical Campus, Vevoor, Manor Road, Palghar (E), Dist. Palghar, Maharashtra-401404
NAAC Accredited with Grade ‘A+’
DEPARTMENT OF COMPUTER ENGINEERING

Low pass filter.

Conclusion : Hence, we have successfully studied the Converting between different color
spaces,The Fourier Transform, High pass filter, Low pass filter.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy