Can Mathematica be used to make anamorphic distortions like these?
h = 6.0; (* eye height *)
h0 = 4.0; (* apparent image height *)
d = 10.0; (* apparent image distance *)
a = d h0/(h - h0); (* actual length of painting *)
The geometry is like this:
Now do the transformation.
myimage = ImageResize[Import@"https://i.stack.imgur.com/k78e8.jpg", Scaled[1/5]];
f[{x_, y_}] := h/(h - y) {x, d}
w0 = h0 Divide @@ ImageDimensions[myimage]
(* 3.20667 *)
i = ImageForwardTransformation[myimage, f,
DataRange -> {{-w0/2, w0/2}, {0, h0}},
PlotRange -> All, Background -> White];
b = a Divide @@ ImageDimensions[i]
(* 4.81791 *)
The resulting transformed image i
:
Using Mathematica's 3D graphics we can paint the transformed image on the ground and view from the appropriate point:
Graphics3D[{Table[{Orange,
Cylinder[{{-b/2, y, 0}, {-b/2, y, 1}}, 0.1],
Cylinder[{{b/2, y, 0}, {b/2, y, 1}}, 0.1]}, {y, d, a + d, 2}],
Texture[i],
Polygon[{{-b/2, d, 0}, {-b/2, d + a, 0}, {b/2, d + a, 0}, {b/2, d, 0}},
VertexTextureCoordinates -> {{0, 0}, {0, 1}, {1, 1}, {1, 0}}]},
ViewVector -> {{0, 0, h}, {0, (d + a)/2, 0}},
ViewAngle -> 0.5, Lighting -> "Neutral", Boxed -> False]
Yes. Simply use: ImagePerspectiveTransformation[]
myimage = Import@"https://i.stack.imgur.com/k78e8.jpg";
For example, define myimage
to be your image. Then:
ImagePerspectiveTransformation[myimage, TransformationFunction[( \!\(\*
TagBox[GridBox[{
{"0", "1", "0.5"},
{"2", "0.5", "0.1"},
{"2", "0", "1.5"}
},
AutoDelete->False,
GridBoxDividers->{
"Columns" -> {{False}}, "ColumnsIndexed" -> {-2 -> True},
"Rows" -> {{False}}, "RowsIndexed" -> {-2 -> True},
"Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
"Rows" -> {{Automatic}}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}}],
#& ]\) )]]
The way to set the geometry for a given viewing position is illustrated here (see Seeing the light: Optics in nature, photography, color, vision and holography by Falk, Brill and Stork): the height of the viewer's eye is given by the top of the right vertical line, a C. Draw a straight line from that point through the right of the base of the transformed image and then continue to the bottom left and use a straightedge accordingly. When viewed from that upper right point, the picture will appear undistorted.