Main Content


Create output view for warping images


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');

Figure contains an axes. The axes contains an object of type image.

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');

Figure contains an axes. The axes with title CenterOutput Bounds Style contains an object of type image.

title('FollowOutput Bounds Style');

Figure contains an axes. The axes with title FollowOutput Bounds Style contains an object of type image.

title('SameAsInput Bounds Style');

Figure contains an axes. The axes with title SameAsInput Bounds Style contains an object of type image.


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.

Affine geometric transformation, specified as an affine2d or affine3d object.

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.

Introduced in R2019b