Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/reference/random_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<!-- pytest-codeblocks:skip -->
```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:

<!-- pytest-codeblocks:skip -->
```python
# Fixed along I, uniform range along J, normal distribution along K
transform = tio.Affine(degrees=(0, (-10, 10), torch.distributions.Normal(0, 5)))
```
14 changes: 13 additions & 1 deletion docs/tutorials/augmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:

<!-- pytest-codeblocks:skip -->
```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):
Expand Down