ImagePerspectiveTransformation[image,m]
applies a linear fractional transform specified by a matrix m to the positions of each pixel in image.
ImagePerspectiveTransformation[image,tf]
uses the TransformationFunction given by tf.
ImagePerspectiveTransformation[image,…,size]
gives an image of the specified size.
ImagePerspectiveTransformation[video,…]
transforms frames of a video.
ImagePerspectiveTransformation
ImagePerspectiveTransformation[image,m]
applies a linear fractional transform specified by a matrix m to the positions of each pixel in image.
ImagePerspectiveTransformation[image,tf]
uses the TransformationFunction given by tf.
ImagePerspectiveTransformation[image,…,size]
gives an image of the specified size.
ImagePerspectiveTransformation[video,…]
transforms frames of a video.
Details and Options
- ImagePerspectiveTransformation is typically used to modify camera position, orientation and field of view of a scene.
- The transformation matrix m corresponds to the following case:
-
image 2D, m 2×2 AffineTransform[m] image 2D, m 3×3 LinearFractionalTransform[m] image 3D, m 3×3 AffineTransform[m] image 3D, m 4×4 LinearFractionalTransform[m] - Possible settings for size are:
-
Automatic automatic image size All same as input image size width explicit width, automatic height {width,height} explicit width and height {width,depth,height} explicit width, depth and height in 3D - ImagePerspectiveTransformation can take the following options:
-
Background 0 background color to use DataRange Automatic range of coordinates in the original image Masking Full region of interest to be transformed Padding 0 padding method PlotRange Automatic range of coordinates in the resulting image Resampling Automatic resampling method - Typical settings for DataRange include:
-
Automatic
in 2D,
in 3DFull
in 2D,
in 3D{{left,right},{bottom,top}} explicit coordinate ranges in 2D {{left,right},{front,back},{bottom,top}} explicit coordinate ranges in 3D - The coordinate system of the resulting image is specified by the PlotRange option. Typical settings include:
-
Automatic same as DataRange settings All try to include all of the transformed pixels Full same ranges as the input image {{left,right},…} explicit coordinate ranges - When PlotRange is not Automatic, size is chosen based on the size of the original image and the ratio of PlotRange and DataRange.
- Masking option can be one of the following:
-
All input image only Full input image and padding mask any mask image - For possible size specifications, see the reference page for ImageResize.
Examples
open all close allBasic Examples (2)
Transform an image using a perspective transformation:
ImagePerspectiveTransformation[[image], (| | | |
| ----- | ----- | - |
| 1 | 1 / 3 | 0 |
| 1 / 3 | 1 | 0 |
| 0 | 1 / 2 | 1 |)]Perspective transformation of a 3D image:
ImagePerspectiveTransformation[[image], (| | | | |
| - | ----- | - | - |
| 1 | 1 / 2 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 1 |)]Scope (13)
Data (4)
Transform a grayscale image by scaling with a factor of
:
ImagePerspectiveTransformation[[image], (1/2)(| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)]ImagePerspectiveTransformation[[image], (1/2)(| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)]ImagePerspectiveTransformation[\!\(\*VideoBox[""]\), (1/2)(| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)]ImagePerspectiveTransformation[[image], (1/2)(| | | |
| - | - | - |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |)]Transformations (8)
2D Images (4)
i = [image];
ImagePerspectiveTransformation[i, (1/2)(| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)]A clockwise rotation of an image:
ImagePerspectiveTransformation[i, (1/2)(| | |
| ------- | ------- |
| Sqrt[3] | -1 |
| 1 | Sqrt[3] |)]ImagePerspectiveTransformation[i, (| | |
| - | -- |
| 1 | -1 |
| 0 | 1 |)]ImagePerspectiveTransformation[i, (| | | |
| - | - | ----- |
| 1 | 0 | 1 / 4 |
| 0 | 1 | 1 / 4 |
| 0 | 0 | 1 |)]A general affine transformation:
ImagePerspectiveTransformation[i, (| | | |
| -- | -- | -- |
| 1 | .2 | .1 |
| .2 | .5 | .1 |
| 0 | 0 | 1 |)]ImagePerspectiveTransformation[i, (| | | |
| -- | -- | -- |
| 1 | .2 | .1 |
| .2 | .5 | .1 |
| .5 | .2 | 1 |)]Use a geometric transformation function to rotate an image:
i = [image];
ImagePerspectiveTransformation[i, RotationTransform[10 °]]Rotate about the opposite image corner:
ImagePerspectiveTransformation[i, RotationTransform[10 °, {1, 1}]]Rotate about the image center:
ImagePerspectiveTransformation[i, RotationTransform[10 °, {0.5, 0.5ImageAspectRatio[i]}]]Shear an image using ShearingTransform:
ImagePerspectiveTransformation[[image], ShearingTransform[20°, {1, 0}, {0, 1}]]Transform an image using a general TransformationFunction object:
ImagePerspectiveTransformation[[image], TransformationFunction[(| | | |
| -- | -- | -- |
| 1 | .2 | .1 |
| .2 | .5 | .1 |
| .5 | .2 | 1 |)]]3D Images (4)
A pure rescaling of a 3D image:
i = [image];
ImagePerspectiveTransformation[i, (3/2)(| | | |
| - | - | - |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |)]Rotate a 3D image around the
axis:
ImagePerspectiveTransformation[i, (1/2)(| | | |
| ------- | -------- | - |
| Sqrt[2] | -Sqrt[2] | 0 |
| Sqrt[2] | Sqrt[2] | 0 |
| 0 | 0 | 2 |)]A pure translation of a 3D image in the vertical direction only:
ImagePerspectiveTransformation[i, (| | | | |
| - | - | - | ----- |
| 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 / 3 |
| 0 | 0 | 0 | 1 |)]Rotate a 3D image using RotationTransform:
ImagePerspectiveTransformation[[image], RotationTransform[30Degree, {0, 1, 0}], PlotRange -> All]An affine transformation of a 3D image:
af = Composition[RotationTransform[30°, {0, 1, 0}], TranslationTransform[{0, 0, 1 / 3}]]ImagePerspectiveTransformation[[image], af]A linear fractional transformation of a 3D image:
ImagePerspectiveTransformation[[image], TransformationFunction[(| | | | |
| --- | --- | -- | --- |
| .8 | -.5 | 0. | .6 |
| .5 | .8 | 0. | -.4 |
| .2 | .2 | .8 | -.3 |
| -.2 | 1 | .2 | .5 |)]]Size (1)
The size value Automatic usually returns images of the same size as the original:
i = [image];ImagePerspectiveTransformation[i, RotationTransform[15 °], Automatic]ImageDimensions[i] == ImageDimensions[%]When PlotRange is specified, the returned image size is derived from the original size and plot range:
ImagePerspectiveTransformation[i, RotationMatrix[15 °], Automatic, PlotRange -> {{0, 2}, {0, 3 / 2}}]Using the value All always returns an image of the same size as the original:
ImagePerspectiveTransformation[i, RotationMatrix[15 °], All, PlotRange -> {{0, 2}, {0, 3 / 2}}]Specify the width of the resulting image:
ImagePerspectiveTransformation[i, RotationTransform[15 °], 200]Specify the width and height of the resulting image:
ImagePerspectiveTransformation[i, RotationTransform[15 °], {100, 100}]ImagePerspectiveTransformation[i, RotationTransform[15 °], Scaled[3]]Use a predefined named size value:
ImagePerspectiveTransformation[i, RotationMatrix[15 °], Tiny]Options (7)
Background (1)
By default, a black background is used:
i = [image];
ImagePerspectiveTransformation[i, RotationTransform[-10 °]]Use a specific color for the background:
ImagePerspectiveTransformation[i, RotationTransform[-10 °], Background -> Gray, Masking -> All]ImagePerspectiveTransformation[i, RotationTransform[-10 °], Background -> Transparent, Masking -> All]Images with an alpha channel use a transparent background by default:
ImagePerspectiveTransformation[SetAlphaChannel[i], RotationTransform[-10 °]]DataRange (2)
By default, the Automatic DataRange is used:
i = [image];
ImagePerspectiveTransformation[i, TranslationTransform[{-0.1, -0.1}], DataRange -> Automatic]Use DataRangeFull when defining translation in pixel coordinates:
ImagePerspectiveTransformation[i, TranslationTransform[{-20, -20}], DataRange -> Full]Specify a custom DataRange:
ImagePerspectiveTransformation[i, TranslationTransform[{-0.1, -0.1}], DataRange -> {{0, 1}, {0, 0.5}}]Use a custom DataRange setting in translating a 3D image:
ImagePerspectiveTransformation[[image], TranslationTransform[{0.3, 0.3, 0.3}], DataRange -> {{0, 1}, {0, 1}, {0, 1}}]Masking (1)
By default, Masking->Full is used, and padding value is used for pixels outside of the original image:
i = [image];
ImagePerspectiveTransformation[i, RotationTransform[20 °], Padding -> "Fixed", Masking -> Full]With Masking->All, a background value is used for pixels outside of the original image:
ImagePerspectiveTransformation[i, RotationTransform[20 °], Background -> Gray, Masking -> All]ImagePerspectiveTransformation[i, RotationTransform[20 °], Masking -> Graphics[{White, Disk[]}, Background -> Black]]Padding (1)
By default, the Padding0 is used:
i = [image];
ImagePerspectiveTransformation[i, RotationMatrix[30 °], PlotRange -> All]ImagePerspectiveTransformation[i, RotationMatrix[30 °], PlotRange -> All, Padding -> LightGreen]ImagePerspectiveTransformation[i, ScalingMatrix[{.5, 1}], Padding -> "Reflected"]PlotRange (1)
By default, PlotRangeAutomatic is used:
i = [image];
ImagePerspectiveTransformation[i, RotationMatrix[20 °]]Use the PlotRangeAll option to show all the transformed pixels from the original image:
ImagePerspectiveTransformation[i, RotationMatrix[20 °], PlotRange -> All]Use a custom PlotRange setting:
ImagePerspectiveTransformation[i, RotationMatrix[20°], PlotRange -> {{0, 2}, {0, 1}}]Use pixel coordinates with PlotRangeFull option:
ImagePerspectiveTransformation[i, RotationTransform[-35°, ImageDimensions[i] / 2], PlotRange -> Full]Resampling (1)
Applications (4)
Use a perspective transformation to modify camera position in an image:
i = [image];Obtain the geometric transformation that maps the four corners of the book to their desired positions:
corners = {{39., 18.}, {13., 100.}, {203., 55.}, {162., 120.}};
newCorners = Tuples[MinMax /@ Transpose[corners]];
HighlightImage[i, {PointSize[Large], Point[corners], Blue, Point[newCorners]}]t = Last@FindGeometricTransform[newCorners, corners]Apply the transformation function to the image:
ImagePerspectiveTransformation[i, t, DataRange -> Full]Remove the perspective distortion of the road:
ImagePerspectiveTransformation[[image], {{1, 0, 0}, {0, 1, 0}, {0, -1 / 320, 1}}, 200, DataRange -> Full, PlotRange -> {{0, 700}, {0, 1100}}]Enhance the perspective effect:
t = FindGeometricTransform[{{207., 54.5}, {208., 274.5}, {136., 114.5}, {136., 231.5}}, {{207, 54.5}, {208., 274.5}, {136., 94.5}, {136., 251.5}}, TransformationClass -> "Perspective"];ImagePerspectiveTransformation[[image], t[[2]], 300, DataRange -> Full, PlotRange -> All]Segment out the building in an image:
i = [image];
c = SelectComponents[ChanVeseBinarize[i, Darker@Yellow, {Automatic, Automatic, 1, 3}], 5000 < #Area < 8000&]Shear the image to straighten up the building:
θ = ComponentMeasurements[c, "Orientation"][[1, 2]];
ImagePerspectiveTransformation[i, ShearingTransform[π / 2 + θ, {1, 0}, {0, 1}], PlotRange -> All]Properties & Relations (2)
ImagePerspectiveTransformation[image,{a,b}] applies AffineTransform[{a,b}] to image:
a = IdentityMatrix[2];
b = {0.1, 0.2};
i = [image];
ImagePerspectiveTransformation[i, {a, b}] == ImagePerspectiveTransformation[i, AffineTransform[{a, b}]]ImagePerspectiveTransformation[image,{a,b,c,d}] applies LinearFractionalTransform[{a,b,c,d}] to image:
a = (| | |
| ------ | ------- |
| Cos[π] | -Sin[π] |
| Sin[π] | Cos[π] |);
c = {-0.2, 0.3};
b = {0.4, 0.5};
d = 1.2;
i = [image];ImagePerspectiveTransformation[i, {a, b, c, d}] == ImagePerspectiveTransformation[i, LinearFractionalTransform[{a, b, c, d}]]Possible Issues (2)
When the function maps some coordinates to infinity, truncated output is displayed:
ImagePerspectiveTransformation[[image], {IdentityMatrix[2], {2, 0}, {-20, 15}, 1}, 200, PlotRange -> All]Non-invertible transformations will give a degenerate result:
ImagePerspectiveTransformation[[image], {{1, 1 / 2}, {2, 1}}, 200]See Also
TransformationFunction FindGeometricTransform ImageForwardTransformation ImageTransformation AffineTransform
Function Repository: ImageShapeMorph
Related Guides
Text
Wolfram Research (2010), ImagePerspectiveTransformation, Wolfram Language function, https://reference.wolfram.com/language/ref/ImagePerspectiveTransformation.html (updated 2021).
CMS
Wolfram Language. 2010. "ImagePerspectiveTransformation." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ImagePerspectiveTransformation.html.
APA
Wolfram Language. (2010). ImagePerspectiveTransformation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImagePerspectiveTransformation.html
BibTeX
@misc{reference.wolfram_2026_imageperspectivetransformation, author="Wolfram Research", title="{ImagePerspectiveTransformation}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ImagePerspectiveTransformation.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_imageperspectivetransformation, organization={Wolfram Research}, title={ImagePerspectiveTransformation}, year={2021}, url={https://reference.wolfram.com/language/ref/ImagePerspectiveTransformation.html}, note=[Accessed: 12-June-2026]}