aidsorb.transforms
This module provides helper functions and classes for transforming point clouds.
Note
The pcd must be a ndarray and have shape of (N, 3+C).
Tip
For implementing your own transforms, have a look at the transforms tutorial. For more flexibility, consider implementing them as callable instances of classes.
- class aidsorb.transforms.Center[source]
Bases:
objectCenter the coordinates of a point cloud by subtracting their centroid.
Examples
>>> pcd = np.array([[1., 2., 3., 5.], [2., 4., 5., 3.]]) >>> center = Center() >>> center(pcd) array([[-0.5, -1. , -1. , 5. ], [ 0.5, 1. , 1. , 3. ]])
>>> center(pcd).mean(axis=0) array([0., 0., 0., 4.])
- class aidsorb.transforms.Identity[source]
Bases:
objectLeave the point cloud unchanged.
Examples
>>> pcd = np.random.randn(300, 4) >>> identity = Identity() >>> np.array_equal(identity(pcd), pcd) True
- class aidsorb.transforms.Jitter(std=0.01)[source]
Bases:
objectJitter the coordinates of a point cloud by adding normal noise.
- Parameters:
std (float, default=0.01) – The standard deviation of the normal noise.
Examples
>>> pcd = np.random.randn(100, 5) >>> jitter = Jitter() >>> new_pcd = jitter(pcd) >>> new_pcd.shape (100, 5)
>>> from aidsorb.utils import split_pcd >>> coords, feats = split_pcd(pcd) >>> new_coords, new_feats = split_pcd(new_pcd)
>>> np.array_equal(new_coords, coords) # Coordinates are affected. False >>> np.array_equal(new_feats, feats) # Features are not affected. True
- class aidsorb.transforms.RandomErase(n_points=5)[source]
Bases:
objectRandomly erase a number of points from the point cloud.
Todo
Consider adding the option for a fraction of points to be erased.
- Parameters:
n_points (int, default=5) – Number of points to be erased.
Examples
>>> pcd = np.random.randn(100, 5) >>> erase = RandomErase(n_points=10) >>> erase(pcd).shape (90, 5)
- class aidsorb.transforms.RandomRotation[source]
Bases:
objectRandomly rotate the coordinates of a point cloud.
Examples
>>> pcd = np.random.randn(25, 4) >>> rot = RandomRotation() >>> new_pcd = rot(pcd) >>> new_pcd.shape (25, 4)
>>> from aidsorb.utils import split_pcd >>> coords, feats = split_pcd(pcd) >>> new_coords, new_feats = split_pcd(new_pcd)
>>> np.array_equal(new_coords, coords) # Coordinates are affected. False >>> np.array_equal(new_feats, feats) # Features are not affected. True
- aidsorb.transforms.transform_pcd(pcd, tfm)[source]
Transform the coordinates of a point cloud.
For molecular point clouds, only rigid transformations are recommended.
- Parameters:
pcd (array of shape (N, 3+C)) – The original point cloud.
tfm (array of shape (3, 3)) – The transformation matrix.
- Returns:
new_pcd – The transformed point cloud.
- Return type:
array of shape (N, 3+C)
- Raises:
ValueError – If
pcdortfmdo not have the expected shape.
Examples
>>> pcd = np.array([[3, -9, 2, 6], [3, 4, -1, 8]]) >>> tfm = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]]) >>> transform_pcd(pcd, tfm) array([[ 9, 3, 2, 6], [-4, 3, -1, 8]])
>>> pcd = np.random.randn(424, 2) # Invalid shape. >>> transform_pcd(pcd, tfm) Traceback (most recent call last): ... ValueError: Expecting array of shape (N, 3+C) but got array of shape (424, 2)!