[CT404]: Assignment 2 progress
@ -5,7 +5,7 @@ import cv2
|
|||||||
image = cv2.imread("./output/otsu.jpg", cv2.IMREAD_GRAYSCALE)
|
image = cv2.imread("./output/otsu.jpg", cv2.IMREAD_GRAYSCALE)
|
||||||
|
|
||||||
# try several different sizes of structuring element (must be odd)
|
# 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
|
# define a disk-shaped structuring element
|
||||||
structuring_element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size))
|
structuring_element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size))
|
||||||
|
|
||||||
|
@ -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)
|
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 163 KiB |
@ -180,6 +180,7 @@ As can be seen from the above output, the optimal value chosen was 129.
|
|||||||
\caption{Image with Otsu thresholding}
|
\caption{Image with Otsu thresholding}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Noise Removal}
|
\subsection{Noise Removal}
|
||||||
\begin{code}
|
\begin{code}
|
||||||
\inputminted[linenos, breaklines, frame=single]{python}{../code/task1/4_noise_removal.py}
|
\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
|
\centering
|
||||||
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_1.jpg}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_1.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 1}}
|
\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}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_3.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 3}}
|
\captionof{figure}{\mintinline{python}{kernel_size = 3}}
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
@ -199,14 +204,22 @@ As can be seen from the above output, the optimal value chosen was 129.
|
|||||||
\centering
|
\centering
|
||||||
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_5.jpg}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_5.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 5}}
|
\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}
|
\end{minipage}
|
||||||
\hfill
|
\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}
|
\begin{minipage}{0.24\textwidth}
|
||||||
\centering
|
\centering
|
||||||
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_9.jpg}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_9.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 9}}
|
\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}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_11.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 11}}
|
\captionof{figure}{\mintinline{python}{kernel_size = 11}}
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
@ -215,8 +228,73 @@ As can be seen from the above output, the optimal value chosen was 129.
|
|||||||
\centering
|
\centering
|
||||||
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_13.jpg}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_13.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 13}}
|
\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}
|
\includegraphics[width=\textwidth]{../code/task1/output/kernel_size_15.jpg}
|
||||||
\captionof{figure}{\mintinline{python}{kernel_size = 15}}
|
\captionof{figure}{\mintinline{python}{kernel_size = 15}}
|
||||||
\end{minipage}
|
\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}
|
\end{document}
|
||||||
|