1

Is it possible to invert an image (the format is png, jpg, bmp) with respect to the given reference circle in LaTeX? Can we transform the individual pixels (e.g. with complex transformations such as Möbius transformation)?

Mathematical inversion is a geometric transformation of the Euclidean plane. In coordinate geometry if the reference circle is the unit circle and P(x,y) is not the origin, then the image of P(x,y) is P'(\frac{x}{x^2+y^2},\frac{y}{x^2+y^2}). In the complex plane if the reference circle is the unit circle and z is not the origin, then its image is z'=\overline{1/z}.

(P.S. How to filter far images of points from the origin?)

csekri
  • 23
  • Welcome! You can't use .bmp anyway, unless you are transforming it. (Certainly won't work here out-of-the-box.) Even if the transformation can/could be done in TeX (it is presumably possible in some abstract sense, provided a digital computer could do it), you will be much better using an external tool. – cfr Jun 10 '17 at 23:11
  • I don't understand the postscript. – cfr Jun 10 '17 at 23:11
  • #cfr If P(x,y) tends to the origin then its image tends to infinity. It is one property of the inversion. Look P'(,) 's denominator! – csekri Jun 10 '17 at 23:15
  • And what about png and jpg? I can convert pictures with external tool (e.g. ffmpeg) so I need only one suitable format. – csekri Jun 10 '17 at 23:33
  • I meant that I would not do the inversion with an external tool. You can't even include non-transformed BMP by default, was my point. I still don't understand the postscript. What does 'filter' mean? – cfr Jun 10 '17 at 23:35
  • Consider the whole picture (original+inverted) in a box/rectangle (for instance 17cm x 8cm)! The picture we want to invert is a (little) bit smaller than this box. If we aren't careful then there are point in the picture whose images goes out of the box. In worse case the image goes to infinity which leads to division by 0 that cause maybe crash during compilation. – csekri Jun 10 '17 at 23:58
  • I understand the problem. I don't understand the proposed solution i.e. what is meant by 'filter'. But I think all this is really beside the point and you need an external processing step anyway. – cfr Jun 11 '17 at 00:18
  • @csekri: If you can read French, there exists an experimental pstricks package dedicated to non-linear transformations named pst-conf, which can do inversions (and also cos z, sin z and ln z transforms) on this site. – Bernard Jun 11 '17 at 00:33
  • @GustavoMezzetti In my opinion both the (unitary) circle and the picture is in the same coordinate system. The (x,y) center and the radius of the circle is given by the user and the coordinates of the picture as well. – csekri Jun 11 '17 at 00:42
  • 1
    @csekri: Indeed, I removed my previous comment because, on second thought, I saw that what you are asking for could make some sense; nonetheless, I still deem it crazy! But according to Bernard’s comment, it is not crazy enough to discourage somebody from actually implementing it… :-) – GuM Jun 11 '17 at 00:57
  • Sorry, but z'=1/z doesn’t flip the unitary circle over? You need to take also the conjugate, don’t you? – GuM Jun 11 '17 at 01:02
  • I calculated it by hand by now. You are right! I used a web page to check it out, but that is wrong there :( – csekri Jun 11 '17 at 01:08
  • @csekri: Probably it is not wrong, they just mean something slightly different. In any case, you don’t need to make complex computations: just think of what the image of i should be. – GuM Jun 11 '17 at 01:22
  • @Bernard But can that transform raster images? – cfr Jun 11 '17 at 01:41
  • same answer of https://tex.stackexchange.com/questions/295100/partial-or-entire-image-blurring-in-tikz applies to here too – percusse Jun 11 '17 at 01:52
  • @cfr: I didn't test it, but there is a \psTransform{image.eps} so I suppose one can try it, first converting a bitmap image to .eps (which may be quite voluminous). – Bernard Jun 11 '17 at 01:53

1 Answers1

2

Because why not?

\documentclass[border=9,tikz]{standalone}
\begin{document}

\pgfmathdeclarefunction{fx}{2}{\pgfmathparse{25*(#1/10+3)/((#1/10+3)^2+(#2/10+0)^2)}}
\pgfmathdeclarefunction{fy}{2}{\pgfmathparse{25*(#2/10+0)/((#1/10+3)^2+(#2/10+0)^2)}}
\pgfmathdeclarefunction{fxx}{2}{\pgfmathparse{fx(#1+1,#2)-fx(#1,#2)}}
\pgfmathdeclarefunction{fxy}{2}{\pgfmathparse{fy(#1+1,#2)-fy(#1,#2)}}
\pgfmathdeclarefunction{fyx}{2}{\pgfmathparse{fx(#1,#2+1)-fx(#1,#2)}}
\pgfmathdeclarefunction{fyy}{2}{\pgfmathparse{fy(#1,#2+1)-fy(#1,#2)}}

\tikz{
    \path(-6,-5)(13,5);
    \draw circle(.05)circle(5)
        (3,0)node{\includegraphics[width=2cm]{lenna.png}};
    \foreach\i in{-10,...,9}{
        \foreach\j in{-10,...,9}{
            \pgfmathsetmacro\aa{fxx(\i,\j)}
            \pgfmathsetmacro\ab{fxy(\i,\j)}
            \pgfmathsetmacro\ba{fyx(\i,\j)}
            \pgfmathsetmacro\bb{fyy(\i,\j)}
            \pgfmathsetmacro\xx{fx (\i,\j)}
            \pgfmathsetmacro\yy{fy (\i,\j)}
            \pgflowlevelobj{
                \pgfsettransformentries{\aa}{\ab}{\ba}{\bb}{\xx cm}{\yy cm}
            }{
                \fill[black!10](1,0)--(0,0)--(0,1);
                \clip(1,0)--(0,0)--(0,1)--cycle;
                \tikzset{shift={(-\i,-\j)}}
                \path(0,0)node{\includegraphics[width=20cm]{lenna.png}};
            }
            \pgfmathsetmacro\aa{fxx(\i  ,\j+1)}
            \pgfmathsetmacro\ab{fxy(\i  ,\j+1)}
            \pgfmathsetmacro\ba{fyx(\i+1,\j  )}
            \pgfmathsetmacro\bb{fyy(\i+1,\j  )}
            \pgfmathsetmacro\xx{fx (\i+1,\j+1)}
            \pgfmathsetmacro\yy{fy (\i+1,\j+1)}
            \pgflowlevelobj{
                \pgfsettransformentries{\aa}{\ab}{\ba}{\bb}{\xx cm}{\yy cm}
            }{
                \clip(0,0)--(-1,0)--(0,-1)--cycle;
                \tikzset{shift={(-\i-1,-\j-1)}}
                \path(0,0)node{\includegraphics[width=20cm]{lenna.png}};
            }
        }
    }
}

\end{document}

code taken from https://tex.stackexchange.com/a/332173/51022.

Symbol 1
  • 36,855