0

I'm trying to replicate Figure 3.15 as shown here so that I can display 3 matrices side by side with captions:

Anyone know of a simple way to get the formatting right? This is what I'm currently using just so that I have something:

\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
\centering
\subcaption{Image matrix, $f(x,y)$}
{$\begin{matrix}
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
\end{matrix}$}
\label{fig:sub1}
\end{subfigure} \vspace{5mm}

\begin{subfigure}{.5\textwidth}
\centering
\subcaption{Spatial Mask, $w(x,y)$}
$\begin{matrix}
1 & 2 & 3 \\ 
4 & 5 & 6 \\ 
7 & 8 & 9 \\ 
\end{matrix}$
\label{fig:sub1}
\end{subfigure} \vspace{5mm}

\begin{subfigure}{.5\textwidth}
\centering
\subcaption{Convolved image}
$\begin{matrix}
0 & 0 & 0 & 0 & 0 \\
0 & 1 & 2 & 3 & 0 \\
0 & 4 & 5 & 6 & 0 \\
0 & 7 & 8 & 9 & 0 \\
0 & 0 & 0 & 0 & 0 \\
\end{matrix}$
\label{fig:sub1}
\end{subfigure}

\end{figure}
1
  • Your attempt seem to be way off as you're creating images that are stacked vertically. Moreover, you're placing captions at the bottom of every matrix. Apart from replicating the output, are you just interested in aligning three matrices next to one another? Where should the sub-captions go, top or bottom?
    – Werner
    Nov 28, 2016 at 23:36

1 Answer 1

1

Here is a rough start. Alignment is done by putting the matrices in a minipage[b] or minipage[t] as required. The matrix environment doesn't have a vertical positioning parameter, so maybe it would be better to use array and put the positioning there, thus giving the opportunity to eliminate the minipage. Or use tikz for positioning, etc. Lots of possibilities for refinement.

\documentclass{article}

\usepackage{subcaption}
\usepackage{amsmath}

\begin{document}
\small
\setlength{\arraycolsep}{2pt}
\begin{figure}

\begin{subfigure}[b]{.3\textwidth}
    Origin of $f(x,y)$\\
  \begin{minipage}[b]{0.5\linewidth}
    $\begin{matrix}
        0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 1 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 \\
      \end{matrix}$
      \vspace{0pt}
  \end{minipage}
  \begin{minipage}[b]{0.2\textwidth}
    $w(x,y)$\\
    $\begin{matrix}
      1 & 2 & 3 \\
      4 & 5 & 6 \\
      7 & 8 & 9 \\
    \end{matrix}$
    \vspace{0pt}
  \end{minipage}
\caption{}\label{fig:sub1}
\end{subfigure}
%
\begin{subfigure}[b]{0.3\textwidth}
  \begin{minipage}[b]{\linewidth}
    Padded $f$\\
    $
    \begin{matrix}
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    \end{matrix}$\vspace{0pt}
  \end{minipage} 
  \caption{}
\end{subfigure}
\vspace{2\baselineskip}

\begin{subfigure}[t]{0.3\textwidth}
  \begin{minipage}[t]{\textwidth}
        Initial position for $w$\\
    $\begin{matrix}
      \cline{1-3}
      |1 & 2 & 3| & 0 & 0 & 0 & 0 & 0 & 0 \\
      |4 & 5 & 6| & 0 & 0 & 0 & 0 & 0 & 0 \\
      |7 & 8 & 9| & 0 & 0 & 0 & 0 & 0 & 0 \\
      \cline{1-3}
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    \end{matrix}$\vspace{0pt}
  \end{minipage} 
  \caption{}
\end{subfigure}
%
\begin{subfigure}[t]{0.3\textwidth}
  \begin{minipage}[t]{\textwidth}
        `full' correlation result\\
    $\begin{matrix}
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 9 & 8 & 7 & 0 & 0 & 0 \\
      0 & 0 & 0 & 6 & 5 & 4 & 0 & 0 & 0 \\
      0 & 0 & 0 & 3 & 2 & 1 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    \end{matrix}$\vspace{0pt}
  \end{minipage} 
  \caption{}
\end{subfigure}
\begin{subfigure}[t]{.3\textwidth}
      `same'~correlation~result\\
$\begin{matrix}
0 & 0 & 0 & 0 & 0 \\
0 & 1 & 2 & 3 & 0 \\
0 & 4 & 5 & 6 & 0 \\
0 & 7 & 8 & 9 & 0 \\
0 & 0 & 0 & 0 & 0 \\
\end{matrix}$
\vspace{4\baselineskip}
\caption{}\label{fig:sub1}
\end{subfigure}

\end{figure}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.