Create randomized 3-D affine transformation
creates an
tform
= randomAffine3daffine3d
object with default property values consistent with the
identity transformation.
specifies the type of affine transformations using name-value pair arguments.tform
= randomAffine3d(Name,Value
)
Create a sample volume.
volumeCube = ones(100,100,100); figure volshow(volumeCube);
Create an affine3d
transformation object that shears 3-D volumes. The randomAffine3d
function picks a shear amount randomly from a continuous uniform distribution within the interval [40, 60] degrees. randomAffine3d
picks a random shear direction aligned with the x-, y-, or z-axis.
tform1 = randomAffine3d('Shear',[40 60]);
J1 = imwarp(volumeCube,tform1);
figure
volshow(J1);
To shear a volume by a different randomly selected amount, create a new affine3d
transformation object. Note the difference in the shear direction.
tform2 = randomAffine3d('Shear',[40 60]);
J2 = imwarp(volumeCube,tform2);
figure
volshow(J2);
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
tform = randomAffine3d('XReflection',true)
'XReflection'
— Random horizontal reflectionfalse
(default) | true
Random horizontal reflection, specified as the comma-separated pair consisting of
'XReflection'
and false
or
true
. When XReflection
is
true
(1
), the transformation
tform
reflects images horizontally with 50% probability. By
default, the transformation does not reflect images in the horizontal
direction.
'YReflection'
— Random vertical reflectionfalse
(default) | true
Random vertical reflection, specified as the comma-separated pair consisting of
'YReflection'
and false
or
true
. When YReflection
is
true
(1
), the transformation
tform
reflects images vertically with 50% probability. By
default, the transformation does not reflect images in the vertical direction.
'ZReflection'
— Random reflection along depthfalse
(default) | true
Random reflection along the depth direction, specified as the comma-separated pair
consisting of 'ZReflection'
and false
or
true
. When ZReflection
is
true
(1
), the transformation
tform
reflects images along the depth direction with 50%
probability. By default, the transformation does not reflect images in the depth
direction.
'Rotation'
— Range of rotation[0 0]
(default) | 2-element numeric vector | function handleRange of rotation applied to the input image, specified as the comma-separated
pair consisting of 'Rotation'
and one of the following. Rotation is
measured in degrees.
2-element numeric vector. The second element must be larger than or equal to
the first element. randomAffine3d
picks a rotation angle
randomly from a continuous uniform distribution within the specified interval.
randomAffine3d
selects a random axis of rotation from the
unit sphere.
function handle of the form
[rotationAxis,theta] = selectRotation
selectRotation
must accept no input arguments. The
function must return two output arguments: rotationAxis
, a
3-element vector defining the axis of rotation, and theta
, a
rotation angle in degrees.Use a function handle to pick rotation angles from a disjoint interval or using a nonuniform probability distribution. You can also use a function handle to specify an axis of rotation. For more information about function handles, see Create Function Handle.
By default, the transformation tform
does not rotate
images.
Example: [-45 45]
'Scale'
— Range of uniform scaling[1 1]
(default) | 2-element numeric vector | function handleRange of uniform (isotropic) scaling applied to the input image, specified as the
comma-separated pair consisting of 'Scale'
and one of the following.
2-element numeric vector. The second element must be larger than or equal to the first element. The scale factor is picked randomly from a continuous uniform distribution within the specified interval.
function handle. The function must accept no input arguments and return the scale factor as a numeric scalar. Use a function handle to pick scale factors from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see Create Function Handle.
By default, the transformation tform
does not scale
images.
Example: [0.5 4]
'Shear'
— Range of shear[0 0]
(default) | 2-element numeric vector | function handleRange of shear applied to the input image, specified as the comma-separated pair
consisting of 'Shear'
and one of the following. Shear is measured
as an angle in degrees, and is in the range (–90, 90).
2-element numeric vector. The second element must be larger than or equal to
the first element. The shear angle is picked randomly from a continuous uniform
distribution within the specified interval. randomAffine3d
applies shear with uniform randomness to one of the principle
x-, y-, and
z-directions with respect to one of the two possible
orthogonal directions.
function handle. The function must accept no input arguments and return the shear angle as a numeric scalar. Use a function handle to pick a shear angle from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see Create Function Handle.
By default, the transformation tform
does not shear images in
the horizontal direction.
Example: [0 45]
'XTranslation'
— Range of horizontal translation[0 0]
(default) | 2-element numeric vector | function handleRange of horizontal translation applied to the input image, specified as the
comma-separated pair consisting of 'XTranslation'
and one of the
following. Translation distance is measured in pixels.
2-element numeric vector. The second element must be larger than or equal to the first element. The translation distance is picked randomly from a continuous uniform distribution within the specified interval.
function handle. The function must accept no input arguments and return the translation distance as a numeric scalar. Use a function handle to pick a translation distance from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see Create Function Handle.
By default, the transformation tform
does not translate
images in the horizontal direction.
Example: [-5 5]
'YTranslation'
— Range of vertical translation[0 0]
(default) | 2-element numeric vector | function handleRange of vertical translation applied to the input image, specified as the
comma-separated pair consisting of 'YTranslation'
and one of the
following. Translation distance is measured in pixels.
2-element numeric vector. The second element must be larger than or equal to the first element. The translation distance is picked randomly from a continuous uniform distribution within the specified interval.
function handle. The function must accept no input arguments and return the translation distance as a numeric scalar. Use a function handle to pick a translation distance from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see Create Function Handle.
By default, the transformation tform
does not translate
images in the vertical direction.
Example: [-5 5]
'ZTranslation'
— Range of translation along depth[0 0]
(default) | 2-element numeric vector | function handleRange of translation along the depth direction applied to the input image,
specified as the comma-separated pair consisting of 'ZTranslation'
and one of the following. Translation distance is measured in pixels.
2-element numeric vector. The second element must be larger than or equal to the first element. The translation distance is picked randomly from a continuous uniform distribution within the specified interval.
function handle. The function must accept no input arguments and return the translation distance as a numeric scalar. Use a function handle to pick a translation distance from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see Create Function Handle.
By default, the transformation tform
does not translate
images in the depth direction.
Example: [-5 5]
tform
— Affine transformationaffine3d
objectAffine transformation, specified as an affine3d
object.
centerCropWindow3d
| imwarp
| randomAffine2d
| randomCropWindow3d
You have a modified version of this example. Do you want to open this example with your edits?