RandomFlip#

class RandomFlip(p=0.5, axes=('x', 'y'))[source]#

Bases: object

Randomly mirror the cloud across one or more axes.

For each requested axis, with probability p negates that coordinate column of coord in place (a reflection through the origin plane). The same sign flip is applied to v3 vertex metadata, aux_position_keys, aux_direction_keys, and normal. Requires coord. Registered as RandomFlip – use this string as the type in a transform=[...] config list.

Parameters:
  • p (float) – per-axis probability of flipping. Defaults to 0.5.

  • axes (str | Sequence[str]) – which of "x", "y", "z" may be flipped. A bare string is wrapped into a single-element tuple. Defaults to ("x", "y").

Note

Each listed axis is tested independently, so multiple axes can flip in a single call.

Example

>>> import numpy as np
>>> from pimm.datasets.transform import RandomFlip
>>> data = {"coord": np.array([[1., 2., 3.], [4., 5., 6.]], dtype="f4")}
>>> out = RandomFlip(p=1.0, axes=("x",))(data)  # p=1 forces an x reflection
>>> out["coord"]  # x column negated, y and z untouched
array([[-1.,  2.,  3.],
       [-4.,  5.,  6.]], dtype=float32)