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}]
up vote 18 down vote accepted

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

  • 1
    Now Mandrill sad ;-( – Yves Klett Apr 30 '13 at 7:47
  • @Yves, after getting stretched and warped a lot, who wouldn't? Lenna was lucky I didn't pick her for this experiment... – J. M. is computer-less Apr 30 '13 at 7:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.