Here's an MWE:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{color}
\usepackage{siunitx}
\definecolor{scalebgcolor}{rgb}{0.08,0.52,0.80}
\newcommand{\scalebarbackground}[5][white]{
\begin{tikzpicture}
\draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\fill [fill=scalebgcolor, fill opacity=0.5] (0.04,1.3em) rectangle (#5*#4/#3+0.04,0.1em);
\draw [#1, line width=0.2em] (0.04,1.2em) -- node[below,inner sep=0.1em, font=\footnotesize] {\SI{#5}{\micro \meter}} (#5*#4/#3+0.04,1.2em);
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{figure}
\subcaptionbox{}[.3\linewidth]{%
\scalebarbackground{%
\includegraphics[width=\linewidth]{example-image-a}%
}{10}{1}{2}%
}%
\subcaptionbox{}[.3\linewidth]{%
\includegraphics[width=\linewidth]{example-image-b}%
}%
\hfill\null%
\caption{ 2nd pic is slighly lower than the 1st. }%
\end{figure}
\end{document}
The result looks like this (the second image is a tiny bit lower):
And that's not a viewer issue, it's really a bit lower:
To fix this, replace \draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
with just \node[anchor=south west,inner sep=0] (image) { #2 };
. Now everything looks fine: