I have a few line drawings (see the attached example; pardon the hideous green), basically black & white with occasional shades of gray and a transparent background (in .png format). I know how to include these pictures in my documents.

Is there a way to “colorize” them, enter image description herefor want of a better word, so that the black lines will appear in a different color? I can, of course, do this in image editing software, but would like to be able to do this on the fly in LaTeX(any flavor).

Any pointers?


2 Answers 2


You can use the decodearray={rmin rmax gmin gmax bmin bmax} option to \includegraphics (the default colour coding is decodearray={0 1 0 1 0 1}).

\includegraphics[decodearray={0 1 0 1 0 1},width=\textwidth]{ingmar.png}\\
\includegraphics[decodearray={1 1 0 1 0 1},width=\textwidth]{ingmar.png}\\
\includegraphics[decodearray={0 1 1 1 0 1},width=\textwidth]{ingmar.png}\\
\includegraphics[decodearray={0 1 0 1 1 1},width=\textwidth]{ingmar.png}

enter image description here

  • This is exactly what I was looking for. Thanks!
    – Ingmar
    Feb 19, 2021 at 12:17
  • 4
    @campa Try example-image.png instead of .pdf. The Decode array will be applied to a single object in the pdf, but an image from a pdf file contains more than a single object, so decodearray isn't used Feb 19, 2021 at 12:23
  • 1
    That's what got me also: make sure the images you work with are actually in RGB (not Grayscale) mode.
    – Ingmar
    Feb 19, 2021 at 17:01
  • 1
    @Ingmar Yes, decodearray will just act on each channel of the image, so if it has only one channel it won't "add" colour. It sort of "tunes" the existing channels. I'm was looking for an official reference on this, but couldn't find one that explains exactly how it works... Feb 19, 2021 at 17:05
  • 2
    decodearray corresponds to the optional /Decode key of an image dictionary in PDF. From the PDF reference, I understand /Decode cannot change color space. If an image uses DeviceGray color space, then /Decode won't make it more "colorful". Jan 6, 2022 at 9:00

TikZ offers lots of possibilities of "filters" (not what kids these days know as filters, please) to apply over an image by using PDF transparency layers. Section 23.3 (Blend Modes) of the TikZ manual explains this feature with the possible "blend modes": normal, multiply, screen, overlay, darken, lighten, color dodge, color burn, hard light, soft light, difference, exclusion, hue, saturation, color and luminosity. Taking the example from this post, you can mix different blend modes to get interesting effects:

enter image description here



  \begin{scope}[blend group=#1]
    \begin{scope}[blend group=#2]
      \node[inner sep=0pt] (logo) {\includegraphics[width=10cm]{hBg1w}};
      \fill[white] (logo.south west) rectangle (logo.north east);
    \fill[red] (logo.south west) rectangle (logo.north east);
  \node (logo.south) [below=.5cm,font=\Large] {#1/#2};



%\colorize{screen}{color dodge}
%\colorize{screen}{color burn}
%\colorize{screen}{hard light}
%\colorize{screen}{soft light}
  • 1
    What's beautiful about this approach is that you can, more or less, map different grays to colors with difference hue. For instance, with some clever combinations you can probably make darker area reddish while making lighter area yellowish.
    – Symbol 1
    Jan 10, 2022 at 3:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .