ElasticDistortion#
- class ElasticDistortion(distortion_params=None)[source]#
Bases:
objectApply smooth random elastic warping to
coord.With 95% probability, displaces
coordin place by a smoothed random noise field: for each(granularity, magnitude)pair, a coarse Gaussian noise grid of spacinggranularityis blurred and trilinearly interpolated to each point, then added scaled bymagnitude. Stacking multiple pairs combines coarse and fine deformations. Requirescoord; a no-op ifcoordis absent ordistortion_paramsisNone. Registered asElasticDistortion– use this string as thetypein atransform=[...]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.Nonemeans[[0.2, 0.4], [0.8, 1.6]]. Defaults toNone.
Note
granularityandmagnitudeare in the same units ascoord, so place this relative to your normalization (before or afterNormalizeCoord) 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