affineOutputView - Create output view for warping images - MATLAB (original) (raw)
Create output view for warping images
Syntax
Description
[Rout](#mw%5F755c0e3a-63f1-47de-963e-1ffe5b6a95a3) = affineOutputView([sizeA](#mw%5Fa3026b7d-0555-4ff3-9c5d-9d1afc4c2244),[tform](#mw%5F7f975454-9a7e-44ae-abdf-f51112b2bdbb))
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](#mw%5F755c0e3a-63f1-47de-963e-1ffe5b6a95a3) = affineOutputView([sizeA](#mw%5Fa3026b7d-0555-4ff3-9c5d-9d1afc4c2244),[tform](#mw%5F7f975454-9a7e-44ae-abdf-f51112b2bdbb),BoundsStyle=[style](#mw%5Fa4b0607b-3aec-4f78-a1f9-fc498b2dc20f))
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.
Examples
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); iptsetpref("ImshowAxesVisible","on") imshow(A)
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.
imshow(BCenterOutput) title("CenterOutput Bounds Style");
imshow(BFollowOutput) title("FollowOutput Bounds Style");
imshow(BSameAsInput) title("SameAsInput Bounds Style");
iptsetpref("ImshowAxesVisible","off")
Input Arguments
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 Object | Description |
---|---|
2-D Geometric Transformations | |
transltform2d | Translation transformation |
rigidtform2d | Rigid transformation: translation and rotation |
simtform2d | Similarity transformation: translation, rotation, and isotropic scaling |
affinetform2d | Affine transformation: translation, rotation, anisotropic scaling, reflection, and shearing |
3-D Geometric Transformations | |
transltform3d | Translation transformation |
rigidtform3d | Rigid transformation: translation and rotation |
simtform3d | Similarity transformation: translation, rotation, and isotropic scaling |
affinetform3d | Affine transformation: translation, rotation, anisotropic scaling, reflection, and shearing |
Note
You can also specify tform
as an affine2d object or an affine3d object. However, these objects are not recommended. For more information, see Version History.
Bounds style, specified as one of the following values.
Style | Description |
---|---|
"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
Spatial referencing, returned as an imref2d or imref3d object. UseRout
as the OutputView
argument of theimwarp function to specify the spatial referencing of the warped output.
Extended Capabilities
Version History
Introduced in R2019b
Starting in R2022b, most Image Processing Toolbox™ functions create and perform geometric transformations using the premultiply convention. Accordingly, you can now specify tform
as a geometric transformation object that uses the premultiply convention, such as an affinetform2d oraffinetform3d object.
Although you can still specify tform
as anaffine2d
or affine3d
object, these objects are not recommended because they use the postmultiply convention. You can streamline your geometric transformation workflows by switching to objects that use the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.
affineOutputView
now supports thread-based environments.