diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/output/1_spatial_domain.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/output/1_spatial_domain.jpg new file mode 100644 index 00000000..5b0eca4f Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/output/1_spatial_domain.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/output/2_frequency_domain_low-pass_filter.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/output/2_frequency_domain_low-pass_filter.jpg new file mode 100644 index 00000000..a9830117 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/output/2_frequency_domain_low-pass_filter.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/task2.py b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/task2.py new file mode 100644 index 00000000..3c31e322 --- /dev/null +++ b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task2/task2.py @@ -0,0 +1,31 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt + +# Task 2.1: Spatial Domain +image = cv2.imread("../../Task2.jpg") + +kernel_size = (15, 15) +variance = 2 + +smoothed_image = cv2.GaussianBlur(image, kernel_size, variance) + +cv2.imwrite("./output/1_spatial_domain.jpg", smoothed_image) + +# Task 2.2: Frequency Domain Low-Pass Filter +gaussian_kernel = cv2.getGaussianKernel(kernel_size[0], variance) +gaussian_kernel_2d = gaussian_kernel @ gaussian_kernel.T +fft_gaussian = np.fft.fft2(gaussian_kernel_2d) + +# shift zero frequency component to center +fft_gaussian_shifted = np.fft.fftshift(fft_gaussian) + +# calculate the magnitude spectrum for visualization +magnitude_spectrum = np.log(np.abs(fft_gaussian_shifted) + 1) + +# Plot the magnitude spectrum (Frequency Domain Representation) +plt.imshow(magnitude_spectrum, cmap='gray') +plt.axis('off') +plt.savefig("./output/2_frequency_domain_low-pass_filter.jpg", bbox_inches='tight', pad_inches=0) + +# Task 2.3: Frequency Domain Filtering diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.pdf b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.pdf index ff125532..028030db 100644 Binary files a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.pdf and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.pdf differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.tex b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.tex index ae80544b..2b77e20c 100644 --- a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.tex +++ b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.tex @@ -295,6 +295,39 @@ I chose to go with \mintinline{python}{kernel_size = 25} as it seemed to give th \subsection{Extraction of Binary Regions of Interest / Connected Components} +\newpage +\section{Filtering of Images in Spatial \& Frequency Domains} +\begin{figure}[H] + \centering + \includegraphics[width=0.5\textwidth]{../Task2.jpg} + \caption{Original Facial Image} +\end{figure} + +\subsection{Spatial Domain} +\begin{code} +\inputminted[firstline=5, lastline=13, linenos, breaklines, frame=single]{python}{../code/task2/task2.py} +\caption{Task 2.1 section of \mintinline{python}{task2.py}} +\end{code} + +After some experimentation, I chose parameter values of \mintinline{python}{kernel_size = (15,15)} and \mintinline{python}{variance = 2} as, in my opinion, these yielded the best balance between blurring imperfections like wrinkles without causing the entire image to become too blurry. + +\begin{figure}[H] + \centering + \includegraphics[width=0.5\textwidth]{../code/task2/output/1_spatial_domain.jpg} + \caption{Output of \mintinline{python}{1_spatial_domain.jpg}} +\end{figure} + +\subsection{Frequency Domain Filtering} +\begin{code} +\inputminted[firstline=15, lastline=29, linenos, breaklines, frame=single]{python}{../code/task2/task2.py} +\caption{Task 2.2 section of \mintinline{python}{task2.py}} +\end{code} + +\begin{figure}[H] + \centering + \includegraphics[width=0.5\textwidth]{../code/task2/output/2_frequency_domain_low-pass_filter.jpg} + \caption{Zero-centered low-pass filter of Gaussian Kernel} +\end{figure} \end{document}