cornucopia.intensity
This module contains transforms that operate on image intensities.
OpConstTransform
Bases: FinalTransform
Base class for arithmetic operations with a constant value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
number or tensor
|
right-hand side of the operation |
required |
op
|
(add, mul)
|
Arithmetic operation |
torch.add
|
value_name
|
str
|
Name used when returning the rhs value |
'value'
|
AddValueTransform
MulValueTransform
FillValueTransform
Bases: FinalTransform
Fills the tensor with a value inside a mask
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
tensor
|
Mask of voxels in which to set the value |
required |
value
|
number or tensor
|
right-hand side of the operation |
required |
mask_name
|
str
|
Name used when returning the mask |
'mask'
|
value_name
|
str
|
Name used when returning the rhs value |
'value'
|
ReturnValueTransform
Bases: FinalTransform
Fills the tensor with a value inside a mask
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
number or tensor
|
right-hand side of the operation |
required |
value_name
|
str
|
Name used when returning the rhs value |
'output'
|
AddMulTransform
Bases: FinalTransform
Constant intensity affine transform: y = x * slope + offset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slope
|
number or tensor
|
Affine slope |
1
|
offset
|
number or tensor
|
Affine offset |
0
|
ClipTransform
Bases: FinalTransform
Clip extremum values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vmin
|
number or tensor
|
Min value |
None
|
vmax
|
number or tensor
|
Max value |
None
|
RandomMulTransform
Bases: RandomizedTransform
Random multiplicative transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Sampler | [pair of] float
|
Bound for multiplicative value |
(0.5, 2)
|
shared
|
(channels, tensors, channels + tensors, '')
|
Apply same transform to all images/channels |
'channels'
|
RandomAddTransform
Bases: RandomizedTransform
Random additive transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Sampler | [pair of] float
|
Bound for additive value |
1
|
shared
|
(channels, tensors, channels + tensors, '')
|
Apply same transform to all images/channels |
'channels'
|
RandomAddMulTransform
Bases: RandomizedTransform
Random intensity affine transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slope
|
Sampler | [pair of] float
|
Bound for slope |
1
|
offset
|
Sampler | [pair of] float
|
Bound for offset |
0.5
|
shared
|
(channels, tensors, channels + tensors, '')
|
Apply same transform to all images/channels |
'channels'
|
SplineUpsampleTransform
Bases: FinalTransform
Upsample a field using spline interpolation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Spline interpolation order |
3
|
prefilter
|
bool
|
Spline prefiltering (True for interpolation, False for spline evaluation) |
False
|
BaseFieldTransform
BaseFieldTransform(shape=5, vmin=0, vmax=1, order=3, slice=None, thickness=None, *, shared=False, **kwargs)
Bases: NonFinalTransform
Base class for transforms that sample a smooth field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
[list of] int
|
Number of spline control points |
5
|
vmin
|
float
|
Minimum value |
0
|
vmax
|
float
|
Maximum value |
1
|
order
|
int
|
Spline order |
3
|
slice
|
int
|
Slice direction, if slicewise. |
None
|
thickness
|
int
|
Slice thickness, if slicewise.
Note that |
None
|
returns
|
[list or dict of] {'input', 'output', 'field'}
|
Which tensor(s) to return |
required |
shared
|
(channels, tensors, channels + tensors, '')
|
Apply the same field to all channels |
'channels'
|
Final
class-attribute
instance-attribute
The transform type returned by make_final.
Next
class-attribute
instance-attribute
The transform type returned by make_final.
make_field
Generate the random coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
int
|
Number of fields to generate |
required |
smallshape
|
list of int
|
Number of spline control points |
required |
fullshape
|
list of int
|
If given, the coefficients will be upsampled to this shape. |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
dtype |
dtype
|
Data type of the generated field. |
device |
device | str
|
Device on which to generate the field. |
Returns:
| Name | Type | Description |
|---|---|---|
field |
(batch, *smallshape) tensor | (batch, *fullshape) tensor
|
If |
upsample_field
Compute the full-sized field from its spline coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff
|
(batch, *smallshape) tensor
|
Spline coefficients |
required |
shape
|
list of int
|
Target shape for the upsampled field |
required |
Returns:
| Name | Type | Description |
|---|---|---|
field |
(batch, *shape) tensor
|
Upsampled field of values |
MulFieldTransform
MulFieldTransform(shape=5, vmin=0, vmax=1, order=3, slice=None, thickness=None, *, shared=False, **kwargs)
Bases: BaseFieldTransform
Smooth multiplicative (bias) field
RandomMulFieldTransform
RandomMulFieldTransform(shape=8, vmax=1, order=3, symmetric=False, *, shared=False, shared_field=None, **kwargs)
Bases: NonFinalTransform
Random multiplicative bias field transform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sampler | int
|
Sampler or Upper bound for number of control points |
8
|
vmax
|
Sampler | float
|
Sampler or Upper bound for maximum value |
1
|
order
|
int
|
Spline order |
3
|
symmetric
|
bool | float
|
If a float, the bias field will take values in
|
False
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
returns |
[list or dict of] {'input', 'output', 'field'}
|
Which tensor(s) to return |
shared |
(channels, tensors, channels + tensors, '')
|
Whether to share random parameters across tensors and/or channels |
shared_field |
(channels, tensors, channels + tensors, '')
|
Whether to share random field across tensors and/or channels.
By default: same as |
RandomSlicewiseMulFieldTransform
RandomSlicewiseMulFieldTransform(shape=8, vmax=1, order=3, slice=None, thickness=32, shape_through=None, *, shared=False, shared_field=None, **kwargs)
Bases: NonFinalTransform
Random multiplicative bias field transform, per slice or slab
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sampler | int
|
Sampler or Upper bound for number of control points |
8
|
vmax
|
Sampler | float
|
Sampler or Upper bound for maximum value |
1
|
order
|
int
|
Spline order |
3
|
slice
|
int
|
Slice axis. If None, sample one randomly |
None
|
thickness
|
Union[Sampler, int]
|
Sampler or Upper bound for slice thickness |
32
|
shape_through
|
Sampler | int
|
Sampler or Upper bound for number of control points
along the slice direction. If None, same as |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
shared |
(channels, tensors, channels + tensors, '')
|
Whether to share random parameters across tensors and/or channels |
shared_field |
(channels, tensors, channels + tensors, '')
|
Whether to share random field across tensors and/or channels.
By default: same as |
AddFieldTransform
AddFieldTransform(shape=5, vmin=0, vmax=1, order=3, slice=None, thickness=None, *, shared=False, **kwargs)
Bases: BaseFieldTransform
Smooth additive (bias) field
RandomAddFieldTransform
RandomAddFieldTransform(shape=8, vmin=-1, vmax=1, order=3, *, shared=False, shared_field=None, **kwargs)
Bases: NonFinalTransform
Random additive bias field transform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sampler | int
|
Sampler or Upper bound for number of control points |
8
|
vmin
|
Sampler | float
|
Sampler or Lower bound for minimum value |
-1
|
vmax
|
Sampler | float
|
Sampler or Upper bound for maximum value |
1
|
order
|
Sampler | int
|
Spline order |
3
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
shared |
(channels, tensors, channels + tensors, '')
|
Whether to share random parameters across tensors and/or channels |
shared_field |
(channels, tensors, channels + tensors, '')
|
Whether to share random field across tensors and/or channels.
By default: same as |
GammaFinalTransform
Bases: FinalTransform
Gamma correction with fixed parameters.
The transform is defined as:
In this transform, vmin and vmax are pre-calculated and fixed,
whereas in GammaTransform, they are computed from the image intensities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
number | (C,) list[number] | (C,) tensor
|
Exponent of the Gamma transform |
1
|
vmin
|
number | (C,) list[number] | (C,) tensor
|
Minimum value for the transform |
0
|
vmax
|
number | (C,) list[number] | (C,) tensor
|
Maximum value for the transform |
1
|
GammaTransform
Bases: NonFinalTransform
Gamma correction
References
- https://en.wikipedia.org/wiki/Gamma_correction
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
float
|
Exponent of the Gamma transform |
1
|
vmin
|
float | None
|
Value to use as the minimum (default: x.min()) |
None
|
vmax
|
float | None
|
Value to use as the maximum (default: x.max()) |
None
|
returns
|
[list or dict] {'input', 'output', 'vmin', 'vmax', 'gamma'}
|
Which tensors to return |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
shared |
(channels, tensors, channels + tensors, '')
|
Use the same vmin/vmax for all channels |
RandomGammaTransform
Bases: NonFinalTransform
Random Gamma transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
Sampler or [pair of] float
|
Sampler or range for the exponent value |
(0.5, 2)
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
shared |
(channels, tensors, channels + tensors, '')
|
Apply same gamma for all images/channels |
shared_minmax |
(channels, tensors, channels + tensors, '', None)
|
Use the same vmin/vmax for all channels. Default: same as |
ZTransform
Bases: NonFinalTransform
Z-transform the data -> zero mean, unit standard deviation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float
|
Target mean. If None, keep the input mean. |
0
|
sigma
|
float
|
Target standard deviation. If None, keep the input sd. |
1
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
shared |
(channels, tensors, channels + tensors, '')
|
Use the same mean/sigma for all images/channels |
QuantileTransform
Bases: NonFinalTransform
Match lower and upper quantiles to (0, 1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmin
|
(0..1)
|
Lower quantile |
0.01
|
pmax
|
(0..1)
|
Upper quantile |
0.99
|
vmin
|
float
|
Lower target value |
0
|
vmax
|
float
|
Upper target value |
1
|
clip
|
bool
|
Clip values outside (vmin, vmax) |
False
|
max_samples
|
int
|
Maximum number of pixels to use for quantile estimation (for speed) |
10000
|
MinMaxTransform
Bases: NonFinalTransform
Match min and max values to (0, 1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vmin
|
float
|
Lower target value |
0
|
vmax
|
float
|
Upper target value |
1
|
clip
|
bool
|
Clip values outside (vmin, vmax) |
False
|