diff --git a/docs/reference/random_parameters.md b/docs/reference/random_parameters.md index c0f8cf1c8..6d96f6256 100644 --- a/docs/reference/random_parameters.md +++ b/docs/reference/random_parameters.md @@ -14,3 +14,27 @@ the specification directly and the transform samples from it at apply time: ## Choice ::: torchio.Choice + +## Distribution + +For continuous randomness, pass any `torch.distributions.Distribution`. +The transform draws a fresh sample from it each time it is applied, so +you can use any distribution supported by PyTorch: + + +```python +import torch +import torchio as tio + +# Sample the rotation angle from a normal distribution (mean 0°, std 5°) +transform = tio.Affine(degrees=torch.distributions.Normal(0, 5)) +``` + +A distribution can also be combined per axis with fixed values and +ranges: + + +```python +# Fixed along I, uniform range along J, normal distribution along K +transform = tio.Affine(degrees=(0, (-10, 10), torch.distributions.Normal(0, 5))) +``` diff --git a/docs/tutorials/augmentation.md b/docs/tutorials/augmentation.md index 5e259a865..8f98b5a1f 100644 --- a/docs/tutorials/augmentation.md +++ b/docs/tutorials/augmentation.md @@ -41,7 +41,7 @@ a tuple gives a uniform range: tio.Affine(degrees=90) # Rotate uniformly between -15° and 15° -tio.Affine(degrees=15) +tio.Affine(degrees=(-15, 15)) # Rotate uniformly between 5° and 20° tio.Affine(degrees=(5, 20)) @@ -63,6 +63,18 @@ You can mix `Choice`, ranges, and fixed values per axis: tio.Affine(degrees=(0, (-10, 10), tio.Choice([-90, 0, 90]))) ``` +For continuous sampling beyond a uniform range, pass any +`torch.distributions.Distribution`. A fresh value is drawn each time +the transform is applied: + + +```python +import torch + +# Sample the rotation angle from a normal distribution (mean 0°, std 5°) +tio.Affine(degrees=torch.distributions.Normal(0, 5)) +``` + ## Probability control Every transform has a `p` parameter (probability of being applied):