diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/1_single_channel_conversion.py b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/1_single_channel_conversion.py new file mode 100644 index 00000000..f414fe2b --- /dev/null +++ b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/1_single_channel_conversion.py @@ -0,0 +1,48 @@ +# Task 1: A Morphological image processing pipeline for medical images +# Task 1.1: Conversion to a single channel image +import cv2 + +# read in original image (in BGR format) +image = cv2.imread("../../Task1.jpg") + +# convert to greyscale +greyscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) +cv2.imwrite("./output/greyscale.jpg", greyscale) + +# convert to blue channel only +b_channel = image.copy() +b_channel[:, :, 1] = 0 +b_channel[:, :, 2] = 0 +cv2.imwrite("./output/b_channel.jpg", b_channel) + +# convert blue channel to greyscale +b_channel_greyscale = cv2.cvtColor(b_channel, cv2.COLOR_BGR2GRAY) +b_channel_greyscale_contrast = b_channel_greyscale.std() +cv2.imwrite("./output/b_channel_greyscale.jpg", b_channel_greyscale) + +# convert to green channel only +g_channel = image.copy() +g_channel[:, :, 0] = 0 +g_channel[:, :, 2] = 0 +cv2.imwrite("./output/g_channel.jpg", g_channel) + +# convert green channel to greyscale +g_channel_greyscale = cv2.cvtColor(g_channel, cv2.COLOR_BGR2GRAY) +g_channel_greyscale_contrast = g_channel_greyscale.std() +cv2.imwrite("./output/g_channel_greyscale.jpg", g_channel_greyscale) + +# convert to red channel only +r_channel = image.copy() +r_channel[:, :, 0] = 0 +r_channel[:, :, 1] = 0 +cv2.imwrite("./output/r_channel.jpg", r_channel) + +# convert red channel to greyscale +r_channel_greyscale = cv2.cvtColor(r_channel, cv2.COLOR_BGR2GRAY) +r_channel_greyscale_contrast = r_channel_greyscale.std() +cv2.imwrite("./output/r_channel_greyscale.jpg", g_channel_greyscale) + +# assess objectively which allows most contrast +print("Blue Channel Greyscale Contrast: " + str(b_channel_greyscale_contrast)) +print("Green Channel Greyscale Contrast: " + str(g_channel_greyscale_contrast)) +print("Red Channel Greyscale Contrast: " + str(r_channel_greyscale_contrast)) diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/b_channel.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/b_channel.jpg new file mode 100644 index 00000000..e04e08c4 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/b_channel.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/b_channel_greyscale.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/b_channel_greyscale.jpg new file mode 100644 index 00000000..642c1199 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/b_channel_greyscale.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/g_channel.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/g_channel.jpg new file mode 100644 index 00000000..ddfc02c8 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/g_channel.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/g_channel_greyscale.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/g_channel_greyscale.jpg new file mode 100644 index 00000000..cc709b0b Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/g_channel_greyscale.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/greyscale.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/greyscale.jpg new file mode 100644 index 00000000..797f4640 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/greyscale.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/r_channel.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/r_channel.jpg new file mode 100644 index 00000000..1c552ee4 Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/r_channel.jpg differ diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/r_channel_greyscale.jpg b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/r_channel_greyscale.jpg new file mode 100644 index 00000000..cc709b0b Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/code/task1/output/r_channel_greyscale.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 new file mode 100644 index 00000000..0e5584be Binary files /dev/null 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 new file mode 100644 index 00000000..4947e5b2 --- /dev/null +++ b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/CT404-Assignment-2.tex @@ -0,0 +1,138 @@ +%! TeX program = lualatex +\documentclass[a4paper]{article} + +% packages +\usepackage{microtype} % Slightly tweak font spacing for aesthetics +\usepackage[english]{babel} % Language hyphenation and typographical rules +\usepackage[final, colorlinks = true, urlcolor = black, linkcolor = black]{hyperref} +\usepackage{changepage} % adjust margins on the fly + +\usepackage{fontspec} +\setmainfont{EB Garamond} +\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono} + +\usepackage{minted} +\usemintedstyle{algol_nu} +\usepackage{xcolor} + +\usepackage{pgfplots} +\pgfplotsset{width=\textwidth,compat=1.9} + +\usepackage{caption} +\newenvironment{code}{\captionsetup{type=listing}}{} +\captionsetup[listing]{skip=0pt} +\setlength{\abovecaptionskip}{5pt} +\setlength{\belowcaptionskip}{5pt} + +\usepackage[yyyymmdd]{datetime} +\renewcommand{\dateseparator}{--} + +\usepackage{titlesec} +% \titleformat{\section}{\LARGE\bfseries}{}{}{}[\titlerule] +% \titleformat{\subsection}{\Large\bfseries}{}{0em}{} +% \titlespacing{\subsection}{0em}{-0.7em}{0em} +% +% \titleformat{\subsubsection}{\large\bfseries}{}{0em}{$\bullet$ } +% \titlespacing{\subsubsection}{1em}{-0.7em}{0em} + +% margins +\addtolength{\hoffset}{-2.25cm} +\addtolength{\textwidth}{4.5cm} +\addtolength{\voffset}{-3.25cm} +\addtolength{\textheight}{5cm} +\setlength{\parskip}{0pt} +\setlength{\parindent}{0in} +% \setcounter{secnumdepth}{0} + +\begin{document} +\hrule \medskip +\begin{minipage}{0.295\textwidth} + \raggedright + \footnotesize + \begin{tabular}{@{}l l} + Name: & Andrew Hayes \\ + Student ID: & 21321503 \\ + E-mail: & \href{mailto://a.hayes18@universityofgalway.ie}{a.hayes18@universityofgalway.ie} \\ + \end{tabular} +\end{minipage} +\begin{minipage}{0.4\textwidth} + \centering + \vspace{0.4em} + \LARGE + \textsc{ct404} \\ +\end{minipage} +\begin{minipage}{0.295\textwidth} + \raggedleft + \today +\end{minipage} +\medskip\hrule +\begin{center} + \normalsize + Assignment 2: Image Processing \& Analysis +\end{center} +\hrule + +\section{A Morphological Image Processing Pipeline for Medical Images} +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{../Task1.jpg} + \caption{Original Skin Biopsy Image} +\end{figure} + +\subsection{Conversion to A Single-Channel Image} +\begin{code} +\inputminted[linenos, breaklines, frame=single]{python}{../code/task1/1_single_channel_conversion.py} +\caption{\mintinline{python}{1_single_channel_conversion.py}} +\end{code} + +Since the image has predominant hues of pink-purple, we would expect the green-channel-only image to be the one that yields the highest contrast, as pink \& purple colours are made up primarily by the blue \& red channels: the dominance of these channels results in little variance in intensity within these channels, and therefore green will have the highest intensity variance. +This is proven true by the text output of the above code, where the standard deviation of the greyscale image based off the green channel alone is by far the highest: +\begin{figure}[H] + \centering + \includegraphics[width=\textwidth]{./images/1_single_channel_conversion_output.png} + \caption{Output of \mintinline{python}{1_single_channel_conversion.py}} +\end{figure} + +\noindent +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../Task1.jpg} + \captionof{figure}{Original image} + \includegraphics[width=\textwidth]{../code/task1/output/greyscale.jpg} + \captionof{figure}{Greyscale original} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/b_channel.jpg} + \captionof{figure}{B-Channel} + \includegraphics[width=\textwidth]{../code/task1/output/b_channel_greyscale.jpg} + \captionof{figure}{B-Greyscale} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/g_channel.jpg} + \captionof{figure}{G-Channel} + \includegraphics[width=\textwidth]{../code/task1/output/g_channel_greyscale.jpg} + \captionof{figure}{G-Greyscale} +\end{minipage} +\hfill +\begin{minipage}{0.24\textwidth} + \centering + \includegraphics[width=\textwidth]{../code/task1/output/r_channel.jpg} + \captionof{figure}{R-Channel} + \includegraphics[width=\textwidth]{../code/task1/output/r_channel_greyscale.jpg} + \captionof{figure}{R-Greyscale} +\end{minipage} + +My selected single-channel image is the greyscale version of the green-channel-only image, as it yields the greatest contrast: +\begin{figure}[H] + \centering + \includegraphics[width=0.5\textwidth]{../code/task1/output/g_channel_greyscale.jpg} + \caption{Selected single-channel image: greyscale green-channel-only} +\end{figure} + +\subsection{Image Enhancement} + +\end{document} diff --git a/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/images/1_single_channel_conversion_output.png b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/images/1_single_channel_conversion_output.png new file mode 100644 index 00000000..6d54cf2b Binary files /dev/null and b/year4/semester1/CT404: Graphics & Image Processing/assignments/assignment2/latex/images/1_single_channel_conversion_output.png differ