trw.transforms.transforms_affine

Module Contents

Classes

TransformAffine

Transform an image using a random affine (2D or 3D) transformation.

Functions

rand_n_2(n_min_max)

Create random values for a list of min/max pairs

_random_affine_2d(translation_random_interval, rotation_random_interval, scaling_factors_random_interval)

Random 2D transformation matrix defined as Tfm = T * Rotation * Scaling

_random_affine_3d(translation_random_interval, rotation_random_interval, scaling_factors_random_interval)

Random 3D transformation matrix defined as Tfm = T * Rotation * Scaling

trw.transforms.transforms_affine.rand_n_2(n_min_max)

Create random values for a list of min/max pairs

Parameters

n_min_max – a matrix of size N * 2 representing N points where n_min_max[:, 0] are the minimum values and n_min_max[:, 1] are the maximum values

Returns

N random values in the defined interval

Examples

To return 3 random values in interval [-1..10], [-2, 20], [-3, 30] respectively: >>> n_min_max = np.asarray([[-1, 10], [-2, 20], [-3, 30]]) >>> rand_n_2(n_min_max)

trw.transforms.transforms_affine._random_affine_2d(translation_random_interval, rotation_random_interval, scaling_factors_random_interval)

Random 2D transformation matrix defined as Tfm = T * Rotation * Scaling

Parameters
  • translation_random_interval – 2 x (min, max) array to specify (min, max) of x and y

  • rotation_random_interval – 1 x (min, max) radian angle

  • scaling_factors_random_interval – 2 x (min, max) or 1 x (min, max) scaling factors for x and y. if size 1 x (min, max), the same random scaling will be applied

Returns

a 3x3 transformation matrix

trw.transforms.transforms_affine._random_affine_3d(translation_random_interval, rotation_random_interval, scaling_factors_random_interval)

Random 3D transformation matrix defined as Tfm = T * Rotation * Scaling

Parameters
  • translation_random_interval – 3 x (min, max) array to specify (min, max) of x and y

  • rotation_random_interval – 1 x (min, max) radian angle

  • scaling_factors_random_interval – 3 x (min, max) or 1 x (min, max) scaling factors for x and y. if size 1 x (min, max), the same random scaling will be applied

Returns

a 4x4 transformation matrix

class trw.transforms.transforms_affine.TransformAffine(translation_min_max: Sequence[numbers.Number], scaling_min_max: Sequence[numbers.Number], rotation_radian_min_max: Sequence[numbers.Number], isotropic: bool = True, criteria_fn: Optional[trw.transforms.transforms.CriteriaFn] = None, padding_mode: str = 'zeros')

Bases: trw.transforms.transforms.TransformBatchWithCriteria

Transform an image using a random affine (2D or 3D) transformation.

Only 2D or 3D supported transformation.

Notes

the scaling and rotational components of the transformation are performed relative to the image.

_transform(self, features_names, batch)