11

I watched this video and became interested in transforming an image. But I have no good idea on how to embed an image in the complex plane using Mathematica.

I have a method that seems to work, but there has to be a better way to do this. Can somebody point me in the right direction?

a = Reverse[ImageData[ImageApplay[Mean,img]]]

f[c_] := Module[{re, im, d1, d2},
   {d1, d2} = Dimensions[a];
   re = Round[Re[d2 c]];
   im = Round[Im[d1 c]];
   If[1 <= re <= d2 && 1 <= im <= d1, a[[im, re]], 1]
];

ListDensityPlot@Table[f[(y + x I)], {x, -1, 1.5, 0.02}, {y, -1, 1.5, 0.02}]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
chyanog
  • 15,542
  • 3
  • 40
  • 78

1 Answers1

21

ImageForwardTransformation[] is the function you want here. To give a concrete example, here's how an image might be transformed by the complex mapping $w=z^3$:

img = ExampleData[{"TestImage", "Mandrill"}];
imgc = ImageForwardTransformation[img, Through[{Re, Im}[(#[[1]] + I #[[2]])^3]] &,
                         Background -> 1,
                         DataRange -> {{-1, 1}, {-1, 1}}, PlotRange -> {{-2, 2}, {-2, 2}}]

cubed mandrill

To see the correspondence with the more usual complex mapping, we show the transformed image along with a suitably transformed Cartesian grid:

ParametricPlot[{Re[(x + I y)^3], Im[(x + I y)^3]}, {x, -1, 1}, {y, -1, 1},
               PlotStyle -> FaceForm[None], Prolog -> {Texture[imgc],
               Polygon[Scaled /@ {{0, 0}, {1, 0}, {1, 1}, {0, 1}},
                       VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]

cubed mandrill with grid


As an example of a nontrivial complex mapping, here is the conformal mapping of a square region to a disk:

img = ExampleData[{"TestImage", "Mandrill"}];
imgc = With[{ω = N[1/2 EllipticK[1/2], 25]},
            ImageForwardTransformation[img, 
                         With[{z = ω (#[[1]] + I #[[2]])},
                              Through[{Re, Im}[JacobiSC[z, 1/2] JacobiDN[z, 1/2]]]] &, 
                         Background -> 1, DataRange -> {{-1, 1}, {-1, 1}}, 
                         PlotRange -> {{-1, 1}, {-1, 1}}]]

mandrill on a disk

Another nontrivial example of a complex mapping (the quincuncial projection) is demonstrated in this answer (though the procedure given there uses ImageTransformation[] instead).

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574