7

I have an old image that I would like to use in a book. But it has some a blotch on it, as well as some other unsightly blemishes. I would like to try to "airbrush" it with Latex, if possible.

To model the scenario, consider the following MWE:

\documentclass{article}
\usepackage{graphicx,xcolor,tikz}
\usepackage{transparent}
\begin{document}
\usetikzlibrary{calc}

\def\blob#1#2{\draw[fill,rounded corners=#1*3mm] (#2) +($(0:#12+#1rnd)$) \foreach \a in {10,20} { -- +($(\a: #12+#1rnd)$) } -- cycle;}

\begin{figure}[!htb] \centering \includegraphics[width=20em,height=33em]{example-image}\llap{\texttransparent{0.5}{\color{green}\rule{20em}{33em}}} \end{figure} \vspace{-125pt}\hspace{125pt}\begin{tikzpicture} \blob{0.2}{1,3} \foreach \a in {15,35} { \fill[green!65!brown] let \p1 = ($(1,3)+(\a+20rnd:2rnd)$), \n1 = {0.15*rnd} in (\p1) circle(\n1); } \end{tikzpicture} \end{document}

which produces the output

enter image description here

As you can see, there are a few blotches of different colors on the example-image.

QUESTION: If this were the image I want to use, without considering the Latex code which produced it, how may I make a reasonably good attempt at airbrushing out these blotches? Also, can somebody inform me as to how I may begin to eliminate one of the faint diagonals, as something similar appears on my actual picture as well?

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36
  • 5
    Is this not a job for a photo editing tool? – Qrrbrbirlbel Dec 05 '22 at 18:00
  • @Qrrbrbirlbel Perhaps, but I am hoping there may be a way to accomplish this in Latex. – DDS Dec 05 '22 at 18:03
  • So, you want to use TikZ to "repair" a picture by overlaying it with some filled paths? Do you really need such an "airbrush" functionality for this? – Jasper Habicht Dec 05 '22 at 19:47
  • @JasperHabicht In the case of the MWE, I know the color used; however, in the actual image, of course, I don't. And so, I'm trying to determine if an "airbrushing" technique may be employed with Latex, or must I try to do externally. – DDS Dec 05 '22 at 20:31
  • Just an idea: overlay the image with a copy of itself clipped to the size of the blotch and moved a bit, so that the blotch is covered. But you would still need to get some soft edges ... maybe using a fading could work. – Jasper Habicht Dec 05 '22 at 20:36
  • @JasperHabicht Thank you for the suggestion. – DDS Dec 05 '22 at 20:37

2 Answers2

11

I would say that this is not a job for LaTeX. -use any photo/image editor with clone tool. It could be done with TikZ, -all dependent on the required result and amount of work.

\documentclass[tikz, border=0.2 cm]{standalone}
\tikzset{%
glow/.style={%
draw=none,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.1,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.1,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.1,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.1,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.1,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.1,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.3,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.3,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.3,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.3,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.3,
preaction={draw, line cap=round, line join=round, line width=0.9*\pgflinewidth, opacity=0.3,
}}}}}}}}}}}}}}
\usetikzlibrary{fadings}
\begin{tikzfadingfrompicture}[name=myfading, color=transparent!0]
\draw[glow, line width=10pt] (-5.5,-3.4) -- (-3,-1.8);
\draw[glow, line width=50pt] (-0.5,1.8) -- (0.2,1.8);
\path (0,0) circle[radius=10]; %encompassing circle for alignment
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\node {\includegraphics[width=\linewidth]{example-image-duck}};
%\fill[path fading=myfading, fit fading=false] (-6,-6) rectangle  (6,6);
\fill[path fading=myfading, fit fading=false] node{\includegraphics[width=\linewidth, trim=25 25 0 0]{example-image-duck}};
\end{tikzpicture}
\end{document}

Original: Duck image with crown

Mask: Duck image with fuzzy lines

Result: Duck image with missing line and crown

Code adapted from https://tex.stackexchange.com/a/569645/8650

8

The idea of this solution is to overlay the image with itself (or with another picture) and add a fading to the overlay so that we get a circle with smooth edges. This way, you can cover some part of the picture with another part of the same picture (or with a part of another picture), quite similar to the functionality of the clone stamp tool provided by, for example, Photoshop.

It is more or less the same solution as the other answer, I just use a shading instead of creating a fading from a picture. This is a bit simpler, the drawback is that you can only use circles or ellipses as "pen".

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}

\pgfdeclareradialshading{radialBrushFading}{\pgfpointorigin}{ color(0pt)=(pgftransparent!0); color(10bp)=(pgftransparent!0); color(25bp)=(pgftransparent!100); color(50bp)=(pgftransparent!100)}% \pgfdeclarefading{radial brush}{\pgfuseshading{radialBrushFading}}%

\def\brushimageoptions{} \def\brushimageshift{(0,0)} \tikzset{ brush/.style args={#1 shift (#2)}{ path fading={ radial brush }, path picture={ \node at ([shift={(#2)}]path picture bounding box.center) {\includegraphics#1}; }, fill=none } }

\begin{document} \begin{tikzpicture}

\node at (0,0) {\includegraphics{example-image-a}}; \fill [brush={{[height=8cm]{example-image-duck}} shift (0,-1)}] (1,1) circle[radius=1.5cm];

\end{tikzpicture}

\end{document}

enter image description here