# Tikzpicture scope background image

I copied and modified the code given on http://www.texample.net/tikz/examples/swan-wave-model/

   \begin{figure}[H]
\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm},on grid]

\begin{scope}[
yshift=-83,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]

% opacity to prevent graphical interference
\fill[white,fill opacity=0.9] (0,0) rectangle (6,6);
\draw[step=5mm, black] (0,0) grid (6,6); %defining grids
\draw[step=1mm, red!50,thin] (0.5,0.5) grid (2,2);  %Nested Grid
\draw[black,very thick] (0,0) rectangle (6,6);%marking borders
\fill[red] (1,1) rectangle (1.5,1.5);
%\includegraphics[scale=1,opacity=0.8]{Pics/face_patch}
%Idem as above, for the n-th grid:
\end{scope}

\begin{scope}[
yshift=90,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=.9] (0,0) rectangle (5,5);
\draw[step=10mm, black] (1,1) grid (4,4);
\draw[black,very thick] (1,1) rectangle (4,4);
\draw[red,dashed] (0,0) rectangle (5,5);
\end{scope}

\draw[-latex,thick](5.8,-.3)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{X}$}
to[out=180,in=90] (3.9,-1);

\draw[-latex,thick,text=black](5.9,5)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
to[out=180,in=90] (3.6,5);
\draw[-latex,dashed,text=black](5.7,3)node[right]{$x_i$}
to[out=180,in=90] (0,5.7);

\draw[-latex,thick,red,text=black](-3.3,-3.2)node[right]{$x_i$}
to[out=180,in=90] (0,-1.4);

\draw[-latex,dashed,red,text=black](4.3,-1.9)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
to[out=180,in=90] (1,-1.3);

\end{tikzpicture}
\end{figure}


What i want is to insert a background picture with some opacity (so that the grid is visible as well as the underlying colors and grids/borders), so that the picture is a background of the first grid (so the image is slanted so to match the grid)

How can i do that? Doing a pure /includegraphics didn't work at all (it didn't slate the image as well as the image size didn't match the grid size)

You need to place the \includegraphics inside a \node, as in the code below. I added some comments, but it's quite straightforward, mostly just place the node at the correct location, and set the proper size for the image.

\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm},on grid]

\begin{scope}[
yshift=-83,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]

% opacity to prevent graphical interference
\fill[white,fill opacity=0.9] (0,0) rectangle (6,6);
\draw[step=5mm, black] (0,0) grid (6,6); %defining grids
\draw[step=1mm, red!50,thin] (0.5,0.5) grid (2,2);  %Nested Grid
\draw[black,very thick] (0,0) rectangle (6,6);%marking borders
\fill[red] (1,1) rectangle (1.5,1.5);

% use a \node to add the image
\node[
opacity=0.5, % set opacity for node, \includegraphics has no opacity option
anchor=south west, % which point of the node to place at the specified coordinate
inner sep=0pt % no padding between image and node border
]
at (0,0) % actually default, so "at (0,0)" is strictly speaking not needed
%
% place the includegraphics in the node
% your grid goes from 0 to 6 with scale=0.5, so its 3cm x 3cm
% the image I used is quadratic, so I set just the width to 3cm
{\includegraphics[width=3cm]{example-image-1x1}};

\end{scope}

\begin{scope}[
yshift=90,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=.9] (0,0) rectangle (5,5);
\draw[step=10mm, black] (1,1) grid (4,4);
\draw[black,very thick] (1,1) rectangle (4,4);
\draw[red,dashed] (0,0) rectangle (5,5);
\end{scope}

\draw[-latex,thick](5.8,-.3)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{X}$}
to[out=180,in=90] (3.9,-1);

\draw[-latex,thick,text=black](5.9,5)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
to[out=180,in=90] (3.6,5);
\draw[-latex,dashed,text=black](5.7,3)node[right]{$x_i$}
to[out=180,in=90] (0,5.7);

\draw[-latex,thick,red,text=black](-3.3,-3.2)node[right]{$x_i$}
to[out=180,in=90] (0,-1.4);

\draw[-latex,dashed,red,text=black](4.3,-1.9)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
to[out=180,in=90] (1,-1.3);

\end{tikzpicture}
\end{document}


Really just for fun: as far as the graphics is concerned, it is the same thing as Torbjørn T.'s nice answer. The "new" thing is that this uses the 3d library and more symbolic coordinates, so it might be easier to customize.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}

\begin{document}
\begin{tikzpicture}[scale=.5,x={({cos(30)},{sin(30)})},z={({-cos(30)},{cos(30)})},
y={(0,1)}]

\begin{scope}[canvas is xz plane at y=-2,transform shape]
\draw[red] (0,0) -- (2,0);
% opacity to prevent graphical interference
\fill[white,fill opacity=0.9] (0,0) rectangle (6,6);
\node[opacity=0.3] at (3,3)
{\includegraphics[width=6cm,height=6cm]{example-image}};
\draw[step=5mm, black] (0,0) grid (6,6); %defining grids
\draw[step=1mm, red!50,thin] (0.5,0.5) grid (2,2);  %Nested Grid
\draw[black,very thick] (0,0) rectangle (6,6);%marking borders
\fill[red] (1,1) rectangle (1.5,1.5) coordinate(x2);
\coordinate (x3) at (1,2);
\coordinate (x1) at (4,0);
\end{scope}

\begin{scope}[canvas is xz plane at y=3,transform shape]
\fill[white,fill opacity=.9] (0,0) rectangle (5,5);
\draw[step=10mm, black] (1,1) grid (4,4);
\draw[black,very thick] (1,1) rectangle (4,4);
\draw[red,dashed] (0,0) rectangle (5,5);
\coordinate (y1) at (2.5,2.5);
\coordinate (y2) at (4,0);
\end{scope}

\draw[-latex,thick](5.8,-.3)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{X}$}
to[out=180,in=90] (x1);

\draw[-latex,thick,text=black](5.9,5)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
to[out=180,in=90] (y2);
\draw[-latex,dashed,text=black](5.7,3)node[right]{$x_i$}
to[out=180,in=90] (y1);

\draw[-latex,thick,red,text=black](-3.3,-2.2)node[right]{$x_i$}
to[out=180,in=90] (x2);

\draw[-latex,dashed,red,text=black](4.3,-2.9)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
to[out=180,in=90] (x3);
\end{tikzpicture}
\end{document}


• Thank you, sadly only one answer can be accepted but this answer is awesome as well. :) This is an interesting approach i might find useful in the future, thanks! – daniels_pa May 25 '18 at 17:45