Main Content


Create output view for warping images

Since R2019b


Rout = affineOutputView(sizeA,tform) takes the size of an input image, sizeA, and an affine geometric transformation, tform, and returns a spatial referencing object, Rout. You can use this object as input to imwarp to control the output limits and grid spacing of a warped image.


Rout = affineOutputView(sizeA,tform,BoundsStyle=style) also specifies constraints on the spatial limits of the output view, such as whether the output view should completely contain the output image or whether the output view should match the input limits.


collapse all

Read and display an image. To see the spatial extents of the image, make the axes visible.

A = imread("kobi.png");
A = imresize(A,0.25);

Create a 2-D affine transformation. This example creates a randomized transformation that consists of scale by a factor in the range [1.2, 2.4], rotation by an angle in the range [-45, 45] degrees, and horizontal translation by a distance in the range [100, 200] pixels.

tform = randomAffine2d("Scale",[1.2,2.4],"XTranslation",[100 200],"Rotation",[-45,45]);

Create three different output views for the image and transformation.

centerOutput = affineOutputView(size(A),tform,"BoundsStyle","CenterOutput");
followOutput = affineOutputView(size(A),tform,"BoundsStyle","FollowOutput");
sameAsInput = affineOutputView(size(A),tform,"BoundsStyle","SameAsInput");

Apply the transformation to the input image using each of the different output view styles.

BCenterOutput = imwarp(A,tform,"OutputView",centerOutput);
BFollowOutput = imwarp(A,tform,"OutputView",followOutput);
BSameAsInput = imwarp(A,tform,"OutputView",sameAsInput);

Display the resulting images.

title("CenterOutput Bounds Style");

title("FollowOutput Bounds Style");

title("SameAsInput Bounds Style");


Input Arguments

collapse all

Input image size, specified as a 2-element numeric vector for 2-D image input or a 3-element numeric vector for 3-D volumetric image input.

Geometric transformation, specified as a geometric transformation object listed in the table.

Geometric Transformation ObjectDescription
2-D Geometric Transformations
transltform2dTranslation transformation
rigidtform2dRigid transformation: translation and rotation
simtform2dSimilarity transformation: translation, rotation, and isotropic scaling
affinetform2dAffine transformation: translation, rotation, anisotropic scaling, reflection, and shearing
3-D Geometric Transformations
transltform3dTranslation transformation
rigidtform3dRigid transformation: translation and rotation
simtform3dSimilarity transformation: translation, rotation, and isotropic scaling
affinetform3dAffine transformation: translation, rotation, anisotropic scaling, reflection, and shearing


You can also specify tform as an affine2d object or an affine3d object. However, these objects are not recommended. For more information, see Compatibility Considerations.

Bounds style, specified as one of the following values.

"CenterOutput"Center the view at the center of the image in output space while allowing translation to move the output image out of view.
"FollowOutput"Set the limits of the output view to completely contain the output image.
"SameAsInput"Set the output limits to be the same as the input limits.

Output Arguments

collapse all

Spatial referencing, returned as an imref2d or imref3d object. Use Rout as the OutputView argument of the imwarp function to specify the spatial referencing of the warped output.

Extended Capabilities

Version History

Introduced in R2019b

expand all