ElasticDistortion#

class ElasticDistortion(distortion_params=None)[source]#

Bases: object

Apply smooth random elastic warping to coord.

With 95% probability, displaces coord in place by a smoothed random noise field: for each (granularity, magnitude) pair, a coarse Gaussian noise grid of spacing granularity is blurred and trilinearly interpolated to each point, then added scaled by magnitude. Stacking multiple pairs combines coarse and fine deformations. Requires coord; a no-op if coord is absent or distortion_params is None. Registered as ElasticDistortion – use this string as the type in a transform=[...] config list.

Parameters:

distortion_params (Sequence[Sequence[float]], optional) – list of [granularity, magnitude] pairs applied in sequence; granularity is the noise-grid spacing in coordinate units and magnitude scales the displacement. None means [[0.2, 0.4], [0.8, 1.6]]. Defaults to None.

Note

granularity and magnitude are in the same units as coord, so place this relative to your normalization (before or after NormalizeCoord) deliberately. Only the spatial coordinates are warped; other point-aligned arrays are unchanged.

Example

>>> import numpy as np, random
>>> from pimm.datasets.transform import ElasticDistortion
>>> np.random.seed(0); random.seed(0)
>>> coord = (np.random.rand(50, 3) * 2).astype("f4")  # spread over a 2-unit box
>>> data = {"coord": coord.copy()}
>>> out = ElasticDistortion(distortion_params=[[0.2, 0.4]])(data)
>>> out["coord"].shape  # same points, smoothly warped (count unchanged)
(50, 3)
>>> bool(np.any(out["coord"] != coord))  # coordinates displaced by the noise field
True
static elastic_distortion(coords, granularity, magnitude)[source]#

Apply elastic distortion on sparse coordinate space. pointcloud: numpy array of (number of points, at least 3 spatial dims) granularity: size of the noise grid (in same scale[m/cm] as the voxel grid) magnitude: noise multiplier