TransWikia.com

Is there a way to "colorize" a line drawing?

TeX - LaTeX Asked on August 15, 2021

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

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}).

documentclass{article}
usepackage{graphicx}
begin{document}
noindent
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}
end{document}

enter image description here

Correct answer by Phelype Oleinik on August 15, 2021

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

documentclass{article}
usepackage{tikz}
begin{document}

includegraphics[width=10cm]{hBg1w.png}

newcommandcolorize[2]{
begin{tikzpicture}
  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);
    end{scope}
    fill[red] (logo.south west) rectangle (logo.north east);
  end{scope}
  node (logo.south) [below=.5cm,font=Large] {#1/#2};
end{tikzpicture}

}

colorize{screen}{overlay}
colorize{overlay}{saturation}

%colorize{screen}{normal}
%colorize{screen}{multiply}
%colorize{screen}{screen}
%colorize{screen}{overlay}
%colorize{screen}{darken}
%colorize{screen}{lighten}
%colorize{screen}{color dodge}
%colorize{screen}{color burn}
%colorize{screen}{hard light}
%colorize{screen}{soft light}
%colorize{screen}{difference}
%colorize{screen}{exclusion}
%colorize{screen}{hue}
%colorize{screen}{saturation}
%colorize{screen}{color}
%colorize{screen}{luminosity}
end{document}

Answered by The Drunken Whaler on August 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP