\section{Introduction}\label{imagetutorial_intro_imagetu}
Image datasets are becoming increasingly popular in deep learning.

mlpack\textquotesingle{}s image saving/loading functionality is based on {\tt stb/}.\section{Table of Contents}\label{imagetutorial_toc_imagetu}
This tutorial is split into the following sections\+:


\begin{DoxyItemize}
\item \doxyref{Introduction}{p.}{imagetutorial_intro_imagetu}
\item \doxyref{Table of Contents}{p.}{imagetutorial_toc_imagetu}
\item \doxyref{Model A\+PI}{p.}{imagetutorial_model_api_imagetu}
\item \doxyref{Image\+Info}{p.}{imagetutorial_imageinfo_api_imagetu}
\item \doxyref{Load}{p.}{imagetutorial_load_api_imagetu}
\item \doxyref{Save}{p.}{imagetutorial_save_api_imagetu}
\end{DoxyItemize}\section{Model A\+PI}\label{imagetutorial_model_api_imagetu}
Image utilities supports loading and saving of images.

It supports filetypes \char`\"{}jpg\char`\"{}, \char`\"{}png\char`\"{}, \char`\"{}tga\char`\"{},\char`\"{}bmp\char`\"{}, \char`\"{}psd\char`\"{}, \char`\"{}gif\char`\"{}, \char`\"{}hdr\char`\"{}, \char`\"{}pic\char`\"{}, \char`\"{}pnm\char`\"{} for loading and \char`\"{}jpg\char`\"{}, \char`\"{}png\char`\"{}, \char`\"{}tga\char`\"{}, \char`\"{}bmp\char`\"{}, \char`\"{}hdr\char`\"{} for saving.

The datatype associated is unsigned char to support R\+GB values in the range 1-\/255. To feed data into the network typecast of {\ttfamily arma\+::\+Mat} may be required. Images are stored in matrix as (width $\ast$ height $\ast$ channels, Number\+Of\+Images). Therefore image\+Matrix.\+col(0) would be the first image if images are loaded in image\+Matrix.\section{Image\+Info}\label{imagetutorial_imageinfo_api_imagetu}
Image\+Info class contains the metadata of the images. 
\begin{DoxyCode}

ImageInfo(\textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} width,
          \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} height,
          \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} channels);
\end{DoxyCode}
 Other public memebers include\+:
\begin{DoxyItemize}
\item quality Compression of the image if saved as jpg (0-\/100).
\end{DoxyItemize}\section{Load}\label{imagetutorial_load_api_imagetu}
Standalone loading of images. 
\begin{DoxyCode}

 \textcolor{keyword}{template}<\textcolor{keyword}{typename} eT>
 \textcolor{keywordtype}{bool} Load(\textcolor{keyword}{const} std::string& filename,
           arma::Mat<eT>& matrix,
           ImageInfo& info,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} fatal,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} transpose);
\end{DoxyCode}


Loading a test image. It also fills up the Image\+Info class object. 
\begin{DoxyCode}
data::ImageInfo info;
data::Load(\textcolor{stringliteral}{"test\_image.png"}, matrix, info, \textcolor{keyword}{false}, \textcolor{keyword}{true});
\end{DoxyCode}


Image\+Info requires height, width, number of channels of the image.


\begin{DoxyCode}
\textcolor{keywordtype}{size\_t} height = 64, width = 64, channels = 1;
data::ImageInfo info(width, height, channels);
\end{DoxyCode}


More than one image can be loaded into the same matrix.

Loading multiple images\+:


\begin{DoxyCode}

 \textcolor{keyword}{template}<\textcolor{keyword}{typename} eT>
 \textcolor{keywordtype}{bool} Load(\textcolor{keyword}{const} std::vector<std::string>& files,
           arma::Mat<eT>& matrix,
           ImageInfo& info,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} fatal,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} transpose);
\end{DoxyCode}



\begin{DoxyCode}
data::ImageInfo info;
std::vector<std::string>> files\{\textcolor{stringliteral}{"test\_image1.bmp"},\textcolor{stringliteral}{"test\_image2.bmp"}\};
data::load(files, matrix, info, \textcolor{keyword}{false}, \textcolor{keyword}{true});
\end{DoxyCode}
\section{Save}\label{imagetutorial_save_api_imagetu}
Save images expects a matrix of type unsigned char in the form (width $\ast$ height $\ast$ channels, Number\+Of\+Images). Just like load it can be used to save one image or multiple images. Besides image data it also expects the shape of the image as input (width, height, channels).

Saving one image\+:


\begin{DoxyCode}

 \textcolor{keyword}{template}<\textcolor{keyword}{typename} eT>
 \textcolor{keywordtype}{bool} Save(\textcolor{keyword}{const} std::string& filename,
           arma::Mat<eT>& matrix,
           ImageInfo& info,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} fatal,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} transpose);
\end{DoxyCode}



\begin{DoxyCode}
data::ImageInfo info;
info.width = info.height = 25;
info.channels = 3;
info.quality = 90;
data::Save(\textcolor{stringliteral}{"test\_image.bmp"}, matrix, info, \textcolor{keyword}{false}, \textcolor{keyword}{true});
\end{DoxyCode}


If the matrix contains more than one image, only the first one is saved.

Saving multiple images\+:


\begin{DoxyCode}

 \textcolor{keyword}{template}<\textcolor{keyword}{typename} eT>
 \textcolor{keywordtype}{bool} Save(\textcolor{keyword}{const} std::vector<std::string>& files,
           arma::Mat<eT>& matrix,
           ImageInfo& info,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} fatal,
           \textcolor{keyword}{const} \textcolor{keywordtype}{bool} transpose);
\end{DoxyCode}



\begin{DoxyCode}
data::ImageInfo info;
info.width = info.height = 25;
info.channels = 3;
info.quality = 90;
std::vector<std::string>> files\{\textcolor{stringliteral}{"test\_image1.bmp"}, \textcolor{stringliteral}{"test\_image2.bmp"}\};
data::Save(files, matrix, info, \textcolor{keyword}{false}, \textcolor{keyword}{true});
\end{DoxyCode}


Multiple images are saved according to the vector of filenames specified. 