diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/4_noise_removal.py b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/4_noise_removal.py index 85ca5c5a..f7ba3c9c 100644 --- a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/4_noise_removal.py +++ b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/4_noise_removal.py @@ -5,7 +5,7 @@ import cv2 image = cv2.imread("./output/otsu.jpg", cv2.IMREAD_GRAYSCALE) # try several different sizes of structuring element (must be odd) -for kernel_size in range(1, 16, 2): +for kernel_size in range(1, 32, 2): # define a disk-shaped structuring element structuring_element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size)) diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/5_extraction_of_binary_region_of_interest.py b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/5_extraction_of_binary_region_of_interest.py new file mode 100644 index 00000000..8bbaaac8 --- /dev/null +++ b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/5_extraction_of_binary_region_of_interest.py @@ -0,0 +1,23 @@ +# Task 1.5: Extraction of Binary Regions of Interest / Connected Components +import cv2 +import numpy as np + +# read in noise-reduced image +image = cv2.imread("./output/kernel_size_25.jpg", cv2.IMREAD_GRAYSCALE) + +# Find connected components +num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(image, connectivity=4) + +# Create an output image (color) to label components +output_img = np.zeros((image.shape[0], image.shape[1], 3), dtype=np.uint8) + +# Apply a single color (e.g., gray) to each component in the output image +for label in range(1, num_labels): # Skip background (label 0) + output_img[labels == label] = (200, 200, 200) # Light gray color for each component + +# Overlay red text labels at component centroids +for i in range(1, num_labels): # Skip background (label 0) + x, y = int(centroids[i][0]), int(centroids[i][1]) + cv2.putText(output_img, str(i), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) # Red color (BGR: (0, 0, 255)) + +cv2.imwrite("./output/region_of_interest.jpg", output_img) diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_17.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_17.jpg new file mode 100644 index 00000000..bf375f7a Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_17.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_19.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_19.jpg new file mode 100644 index 00000000..2a9a5d7a Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_19.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_21.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_21.jpg new file mode 100644 index 00000000..a8f3ba00 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_21.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_23.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_23.jpg new file mode 100644 index 00000000..debc229b Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_23.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_25.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_25.jpg new file mode 100644 index 00000000..100edd31 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_25.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_27.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_27.jpg new file mode 100644 index 00000000..9b9300a2 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_27.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_29.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_29.jpg new file mode 100644 index 00000000..30496cfa Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_29.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_31.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_31.jpg new file mode 100644 index 00000000..891c12d1 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/kernel_size_31.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/region_of_interest.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/region_of_interest.jpg new file mode 100644 index 00000000..5c9dadf3 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/region_of_interest.jpg differ 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 0d45725d..ff125532 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 bfa9163e..ae80544b 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 @@ -180,6 +180,7 @@ As can be seen from the above output, the optimal value chosen was 129. \caption{Image with Otsu thresholding} \end{figure} + \subsection{Noise Removal} \begin{code} \inputminted[linenos, breaklines, frame=single]{python}{../code/task1/4_noise_removal.py} @@ -191,6 +192,10 @@ As can be seen from the above output, the optimal value chosen was 129. \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_1.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 1}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_3.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 3}} \end{minipage} @@ -199,14 +204,22 @@ As can be seen from the above output, the optimal value chosen was 129. \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_5.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 5}} - \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_7.jpg} - \captionof{figure}{\mintinline{python}{kernel_size = 7}} \end{minipage} \hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_7.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 7}} +\end{minipage} + \begin{minipage}{0.24\textwidth} \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_9.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 9}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_11.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 11}} \end{minipage} @@ -215,8 +228,73 @@ As can be seen from the above output, the optimal value chosen was 129. \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_13.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 13}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_15.jpg} \captionof{figure}{\mintinline{python}{kernel_size = 15}} \end{minipage} +\noindent +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_17.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 17}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_19.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 19}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_21.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 21}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_23.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 23}} +\end{minipage} + +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_25.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 25}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_27.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 27}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_29.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 29}} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/kernel_size_31.jpg} + \captionof{figure}{\mintinline{python}{kernel_size = 31}} +\end{minipage} + +I chose to go with \mintinline{python}{kernel_size = 25} as it seemed to give the optimal balance between removing noise without significantly reducing the size of the remaining fat globules . + +\begin{figure}[H] + \centering + \includegraphics[width=0.5\textwidth]{../code/task1/output/kernel_size_25.jpg} + \caption{Chosen noise threshold: \mintinline{python}{kernel_size = 25}} +\end{figure} + +\subsection{Extraction of Binary Regions of Interest / Connected Components} + + + \end{document}