Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}]
share|improve this question
2  
See shuisman.com/?p=1401#more-1401 and this question –  cormullion Mar 14 '13 at 12:12
    
Thanks, it's a nice link. –  chyaong Mar 14 '13 at 12:28
add comment

1 Answer

up vote 11 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).

share|improve this answer
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. Apr 30 '13 at 7:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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