Shortcuts

rising.transforms.functional

Provides a functional interface for transforms (usually working on single tensors rather then collections thereof). All transformations are implemented to work on batched tensors. Implementations include:

  • Affine Transforms

  • Channel Transforms

  • Cropping Transforms

  • Device Transforms

  • Intensity Transforms

  • Spatial Transforms

  • Tensor Transforms

  • Utility Transforms

Affine Transforms

rising.transforms.functional.affine.affine_image_transform(image_batch, matrix_batch, output_size=None, adjust_size=False, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False, reverse_order=False)[source][source]

Performs an affine transformation on a batch of images

Parameters
  • image_batch (Tensor) – the batch to transform. Should have shape of [N, C, NDIM]

  • matrix_batch (Tensor) – a batch of affine matrices with shape [N, NDIM, NDIM+1]

  • output_size (Optional[tuple]) – if given, this will be the resulting image size. Defaults to None

  • adjust_size (bool) – if True, the resulting image size will be calculated dynamically to ensure that the whole image fits.

  • interpolation_mode (str) – interpolation mode to calculate output values ‘bilinear’ | ‘nearest’. Default: ‘bilinear’

  • padding_mode (str) – padding mode for outside grid values ‘zeros’ | ‘border’ | ‘reflection’. Default: ‘zeros’

  • align_corners (bool) – Geometrically, we consider the pixels of the input as squares rather than points. If set to True, the extrema (-1 and 1) are considered as referring to the center points of the input’s corner pixels. If set to False, they are instead considered as referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic.

Returns

transformed image

Return type

torch.Tensor

Warning

When align_corners = True, the grid positions depend on the pixel size relative to the input image size, and so the locations sampled by grid_sample() will differ for the same input given at different resolutions (that is, after being upsampled or downsampled).

Notes

output_size and adjust_size are mutually exclusive. If None of them is set, the resulting image will have the same size as the input image.

rising.transforms.functional.affine.affine_point_transform(point_batch, matrix_batch)[source][source]

Function to perform an affine transformation onto point batches

Parameters
  • point_batch (Tensor) – a point batch of shape [N, NP, NDIM] NP is the number of points, N is the batch size, NDIM is the number of spatial dimensions

  • matrix_batch (Tensor) – torch.Tensor a batch of affine matrices with shape [N, NDIM, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions

Returns

the batch of transformed points in cartesian coordinates)

[N, NP, NDIM] NP is the number of points, N is the batch size, NDIM is the number of spatial dimensions

Return type

torch.Tensor

rising.transforms.functional.affine.create_rotation(rotation, batchsize, ndim, degree=False, device=None, dtype=None)[source][source]

Formats the given scale parameters to a homogeneous transformation matrix

Parameters
  • rotation (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation angle of 0

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • degree (bool) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

Returns

the homogeneous transformation matrix

[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

rising.transforms.functional.affine.create_scale(scale, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source]

Formats the given scale parameters to a homogeneous transformation matrix

Parameters
  • scale (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

  • image_transform (bool) – inverts the scale matrix to match expected behavior when applied to an image, e.g. scale>1 increases the size of an image but decrease the size of an grid

Returns

the homogeneous transformation matrix

[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

rising.transforms.functional.affine.create_translation(offset, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source]

Formats the given translation parameters to a homogeneous transformation matrix

Parameters
  • offset (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

  • image_transform (bool) – bool inverts the translation matrix to match expected behavior when applied to an image, e.g. translation > 0 should move the image in the positive direction of an axis but the grid in the negative direction

Returns

the homogeneous transformation matrix [N, NDIM + 1, NDIM + 1],

N is the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

rising.transforms.functional.affine.parametrize_matrix(scale, rotation, translation, batchsize, ndim, degree=False, device=None, dtype=None, image_transform=True)[source][source]

Formats the given scale parameters to a homogeneous transformation matrix

Parameters
  • scale (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1

  • rotation (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation factor of 1

  • translation (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • degree (bool) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

  • image_transform (bool) – bool adjusts transformation matrices such that they match the expected behavior on images (see create_scale() and create_translation() for more info)

Returns

the transformation matrix [N, NDIM, NDIM+1], N is

the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

affine_image_transform

rising.transforms.functional.affine.affine_image_transform(image_batch, matrix_batch, output_size=None, adjust_size=False, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False, reverse_order=False)[source][source]

Performs an affine transformation on a batch of images

Parameters
  • image_batch (Tensor) – the batch to transform. Should have shape of [N, C, NDIM]

  • matrix_batch (Tensor) – a batch of affine matrices with shape [N, NDIM, NDIM+1]

  • output_size (Optional[tuple]) – if given, this will be the resulting image size. Defaults to None

  • adjust_size (bool) – if True, the resulting image size will be calculated dynamically to ensure that the whole image fits.

  • interpolation_mode (str) – interpolation mode to calculate output values ‘bilinear’ | ‘nearest’. Default: ‘bilinear’

  • padding_mode (str) – padding mode for outside grid values ‘zeros’ | ‘border’ | ‘reflection’. Default: ‘zeros’

  • align_corners (bool) – Geometrically, we consider the pixels of the input as squares rather than points. If set to True, the extrema (-1 and 1) are considered as referring to the center points of the input’s corner pixels. If set to False, they are instead considered as referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic.

Returns

transformed image

Return type

torch.Tensor

Warning

When align_corners = True, the grid positions depend on the pixel size relative to the input image size, and so the locations sampled by grid_sample() will differ for the same input given at different resolutions (that is, after being upsampled or downsampled).

Notes

output_size and adjust_size are mutually exclusive. If None of them is set, the resulting image will have the same size as the input image.

affine_point_transform

rising.transforms.functional.affine.affine_point_transform(point_batch, matrix_batch)[source][source]

Function to perform an affine transformation onto point batches

Parameters
  • point_batch (Tensor) – a point batch of shape [N, NP, NDIM] NP is the number of points, N is the batch size, NDIM is the number of spatial dimensions

  • matrix_batch (Tensor) – torch.Tensor a batch of affine matrices with shape [N, NDIM, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions

Returns

the batch of transformed points in cartesian coordinates)

[N, NP, NDIM] NP is the number of points, N is the batch size, NDIM is the number of spatial dimensions

Return type

torch.Tensor

parametrize_matrix

rising.transforms.functional.affine.parametrize_matrix(scale, rotation, translation, batchsize, ndim, degree=False, device=None, dtype=None, image_transform=True)[source][source]

Formats the given scale parameters to a homogeneous transformation matrix

Parameters
  • scale (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1

  • rotation (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation factor of 1

  • translation (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • degree (bool) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

  • image_transform (bool) – bool adjusts transformation matrices such that they match the expected behavior on images (see create_scale() and create_translation() for more info)

Returns

the transformation matrix [N, NDIM, NDIM+1], N is

the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

create_rotation

rising.transforms.functional.affine.create_rotation(rotation, batchsize, ndim, degree=False, device=None, dtype=None)[source][source]

Formats the given scale parameters to a homogeneous transformation matrix

Parameters
  • rotation (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation angle of 0

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • degree (bool) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

Returns

the homogeneous transformation matrix

[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

create_rotation_2d

rising.transforms.functional.affine.create_rotation_2d(sin, cos)[source][source]

Create a 2d rotation matrix

Parameters
  • sin (Tensor) – sin value to use for rotation matrix, [1]

  • cos (Tensor) – cos value to use for rotation matrix, [1]

  • Returns – torch.Tensor: rotation matrix, [2, 2]

Return type

Tensor

create_rotation_3d

rising.transforms.functional.affine.create_rotation_3d(sin, cos)[source][source]

Create a 3d rotation matrix which sequentially applies the rotation around axis (rot axis 0 -> rot axis 1 -> rot axis 2)

Parameters
  • sin (Tensor) – sin values to use for the rotation, (axis 0, axis 1, axis 2)[3]

  • cos (Tensor) – cos values to use for the rotation, (axis 0, axis 1, axis 2)[3]

Returns

rotation matrix, [3, 3]

Return type

torch.Tensor

create_rotation_3d_0

rising.transforms.functional.affine.create_rotation_3d_0(sin, cos)[source][source]

Create a rotation matrix around the zero-th axis

Parameters
  • sin (Tensor) – sin value to use for rotation matrix, [1]

  • cos (Tensor) – cos value to use for rotation matrix, [1]

Returns

rotation matrix, [3, 3]

Return type

torch.Tensor

create_rotation_3d_1

rising.transforms.functional.affine.create_rotation_3d_1(sin, cos)[source][source]

Create a rotation matrix around the first axis

Parameters
  • sin (Tensor) – sin value to use for rotation matrix, [1]

  • cos (Tensor) – cos value to use for rotation matrix, [1]

Returns

rotation matrix, [3, 3]

Return type

torch.Tensor

create_rotation_3d_2

rising.transforms.functional.affine.create_rotation_3d_2(sin, cos)[source][source]

Create a rotation matrix around the second axis

Parameters
  • sin (Tensor) – sin value to use for rotation matrix, [1]

  • cos (Tensor) – cos value to use for rotation matrix, [1]

Returns

rotation matrix, [3, 3]

Return type

torch.Tensor

create_scale

rising.transforms.functional.affine.create_scale(scale, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source]

Formats the given scale parameters to a homogeneous transformation matrix

Parameters
  • scale (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

  • image_transform (bool) – inverts the scale matrix to match expected behavior when applied to an image, e.g. scale>1 increases the size of an image but decrease the size of an grid

Returns

the homogeneous transformation matrix

[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

create_translation

rising.transforms.functional.affine.create_translation(offset, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source]

Formats the given translation parameters to a homogeneous transformation matrix

Parameters
  • offset (Union[int, Sequence[int], float, Sequence[float], Tensor, AbstractParameter, Sequence[AbstractParameter]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0

  • batchsize (int) – the number of samples per batch

  • ndim (int) – the dimensionality of the transform

  • device (Union[device, str, None]) – the device to put the resulting tensor to. Defaults to the torch default device

  • dtype (Union[dtype, str, None]) – the dtype of the resulting trensor. Defaults to the torch default dtype

  • image_transform (bool) – bool inverts the translation matrix to match expected behavior when applied to an image, e.g. translation > 0 should move the image in the positive direction of an axis but the grid in the negative direction

Returns

the homogeneous transformation matrix [N, NDIM + 1, NDIM + 1],

N is the batch size and NDIM is the number of spatial dimensions

Return type

torch.Tensor

expand_scalar_param

rising.transforms.functional.affine.expand_scalar_param(param, batchsize, ndim)[source][source]

Bring affine params to shape (batchsize, ndim)

Parameters
Returns

affine params in correct shape

Return type

torch.Tensor

Channel Transforms

rising.transforms.functional.channel.one_hot_batch(target, num_classes=None, dtype=None)[source][source]

Compute one hot for input tensor (assumed to a be batch and thus saved into first dimension -> input should only have one channel)

Parameters
  • target (Tensor) – long tensor to be converted

  • num_classes (Optional[int]) – number of classes. If num_classes is None, the maximum of target is used

  • dtype (Optional[dtype]) – optionally changes the dtype of the onehot encoding

Returns

one hot encoded tensor

Return type

torch.Tensor

one_hot_batch

rising.transforms.functional.channel.one_hot_batch(target, num_classes=None, dtype=None)[source][source]

Compute one hot for input tensor (assumed to a be batch and thus saved into first dimension -> input should only have one channel)

Parameters
  • target (Tensor) – long tensor to be converted

  • num_classes (Optional[int]) – number of classes. If num_classes is None, the maximum of target is used

  • dtype (Optional[dtype]) – optionally changes the dtype of the onehot encoding

Returns

one hot encoded tensor

Return type

torch.Tensor

Cropping Transforms

rising.transforms.functional.crop.crop(data, corner, size)[source][source]

Extract crop from last dimensions of data

Args: data: input tensor corner: top left corner point size: size of patch

Returns

cropped data

Return type

torch.Tensor

rising.transforms.functional.crop.center_crop(data, size)[source][source]

Crop patch from center

Args: data: input tensor size: size of patch

Returns

output tensor cropped from input tensor

Return type

torch.Tensor

rising.transforms.functional.crop.random_crop(data, size, dist=0)[source][source]

Crop random patch/volume from input tensor

Parameters
Returns

cropped output

Return type

torch.Tensor

crop

rising.transforms.functional.crop.crop(data, corner, size)[source][source]

Extract crop from last dimensions of data

Args: data: input tensor corner: top left corner point size: size of patch

Returns

cropped data

Return type

torch.Tensor

center_crop

rising.transforms.functional.crop.center_crop(data, size)[source][source]

Crop patch from center

Args: data: input tensor size: size of patch

Returns

output tensor cropped from input tensor

Return type

torch.Tensor

random_crop

rising.transforms.functional.crop.random_crop(data, size, dist=0)[source][source]

Crop random patch/volume from input tensor

Parameters
Returns

cropped output

Return type

torch.Tensor

Intensity Transforms

rising.transforms.functional.intensity.norm_range(data, min, max, per_channel=True, out=None)[source][source]

Scale range of tensor

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • min (float) – minimal value

  • max (float) – maximal value

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved in here

Returns

normalized data

Return type

torch.Tensor

rising.transforms.functional.intensity.norm_min_max(data, per_channel=True, out=None, eps=1e-08)[source][source]

Scale range to [0,1]

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved in here

  • eps (Optional[float]) – small constant for numerical stability. If None, no factor constant will be added

Returns

scaled data

Return type

torch.Tensor

rising.transforms.functional.intensity.norm_zero_mean_unit_std(data, per_channel=True, out=None, eps=1e-08)[source][source]

Normalize mean to zero and std to one

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved in here

  • eps (Optional[float]) – small constant for numerical stability. If None, no factor constant will be added

Returns

normalized data

Return type

torch.Tensor

rising.transforms.functional.intensity.norm_mean_std(data, mean, std, per_channel=True, out=None)[source][source]

Normalize mean and std with provided values

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • mean (Union[float, Sequence]) – used for mean normalization

  • std (Union[float, Sequence]) – used for std normalization

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved into out

Returns

normalized data

Return type

torch.Tensor

rising.transforms.functional.intensity.add_noise(data, noise_type, out=None, **kwargs)[source][source]

Add noise to input

Parameters
  • data (Tensor) – input data

  • noise_type (str) – supports all inplace functions of a pytorch tensor

  • out (Optional[Tensor]) – if provided, result is saved in here

  • kwargs – keyword arguments passed to generating function

Returns

data with added noise

Return type

torch.Tensor

See also

torch.Tensor.normal_(), torch.Tensor.exponential_()

rising.transforms.functional.intensity.add_value(data, value, out=None)[source][source]

Increase brightness additively by value (currently this functions is intended as an interface in case additional functionality should be added to transform)

Parameters
  • data (Tensor) – input data

  • value (float) – additive value

  • out (Optional[Tensor]) – if provided, result is saved in here

Returns

augmented data

Return type

torch.Tensor

rising.transforms.functional.intensity.gamma_correction(data, gamma)[source][source]

Apply gamma correction to data (currently this functions is intended as an interface in case additional functionality should be added to transform)

Parameters
  • data (Tensor) – input data

  • gamma (float) – gamma for correction

Returns

gamma corrected data

Return type

torch.Tensor

rising.transforms.functional.intensity.scale_by_value(data, value, out=None)[source][source]

Increase brightness scaled by value (currently this functions is intended as an interface in case additional functionality should be added to transform)

Parameters
  • data (Tensor) – input data

  • value (float) – scaling value

  • out (Optional[Tensor]) – if provided, result is saved in here

Returns

augmented data

Return type

torch.Tensor

rising.transforms.functional.intensity.clamp(data, min, max, out=None)[source][source]

Clamp tensor to minimal and maximal value

Parameters
Returns

clamped tensor

Return type

Tensor

norm_range

rising.transforms.functional.intensity.norm_range(data, min, max, per_channel=True, out=None)[source][source]

Scale range of tensor

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • min (float) – minimal value

  • max (float) – maximal value

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved in here

Returns

normalized data

Return type

torch.Tensor

norm_min_max

rising.transforms.functional.intensity.norm_min_max(data, per_channel=True, out=None, eps=1e-08)[source][source]

Scale range to [0,1]

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved in here

  • eps (Optional[float]) – small constant for numerical stability. If None, no factor constant will be added

Returns

scaled data

Return type

torch.Tensor

norm_zero_mean_unit_std

rising.transforms.functional.intensity.norm_zero_mean_unit_std(data, per_channel=True, out=None, eps=1e-08)[source][source]

Normalize mean to zero and std to one

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved in here

  • eps (Optional[float]) – small constant for numerical stability. If None, no factor constant will be added

Returns

normalized data

Return type

torch.Tensor

norm_mean_std

rising.transforms.functional.intensity.norm_mean_std(data, mean, std, per_channel=True, out=None)[source][source]

Normalize mean and std with provided values

Parameters
  • data (Tensor) – input data. Per channel option supports [C,H,W] and [C,H,W,D].

  • mean (Union[float, Sequence]) – used for mean normalization

  • std (Union[float, Sequence]) – used for std normalization

  • per_channel (bool) – range is normalized per channel

  • out (Optional[Tensor]) – if provided, result is saved into out

Returns

normalized data

Return type

torch.Tensor

add_noise

rising.transforms.functional.intensity.add_noise(data, noise_type, out=None, **kwargs)[source][source]

Add noise to input

Parameters
  • data (Tensor) – input data

  • noise_type (str) – supports all inplace functions of a pytorch tensor

  • out (Optional[Tensor]) – if provided, result is saved in here

  • kwargs – keyword arguments passed to generating function

Returns

data with added noise

Return type

torch.Tensor

See also

torch.Tensor.normal_(), torch.Tensor.exponential_()

add_value

rising.transforms.functional.intensity.add_value(data, value, out=None)[source][source]

Increase brightness additively by value (currently this functions is intended as an interface in case additional functionality should be added to transform)

Parameters
  • data (Tensor) – input data

  • value (float) – additive value

  • out (Optional[Tensor]) – if provided, result is saved in here

Returns

augmented data

Return type

torch.Tensor

gamma_correction

rising.transforms.functional.intensity.gamma_correction(data, gamma)[source][source]

Apply gamma correction to data (currently this functions is intended as an interface in case additional functionality should be added to transform)

Parameters
  • data (Tensor) – input data

  • gamma (float) – gamma for correction

Returns

gamma corrected data

Return type

torch.Tensor

scale_by_value

rising.transforms.functional.intensity.scale_by_value(data, value, out=None)[source][source]

Increase brightness scaled by value (currently this functions is intended as an interface in case additional functionality should be added to transform)

Parameters
  • data (Tensor) – input data

  • value (float) – scaling value

  • out (Optional[Tensor]) – if provided, result is saved in here

Returns

augmented data

Return type

torch.Tensor

Spatial Transforms

rising.transforms.functional.spatial.mirror(data, dims)[source][source]

Mirror data at dims

Parameters
Returns

tensor with mirrored dimensions

Return type

torch.Tensor

rising.transforms.functional.spatial.rot90(data, k, dims)[source][source]

Rotate 90 degrees around dims

Parameters
Returns

tensor with mirrored dimensions

Return type

torch.Tensor

rising.transforms.functional.spatial.resize_native(data, size=None, scale_factor=None, mode='nearest', align_corners=None, preserve_range=False)[source][source]

Down/up-sample sample to either the given size or the given scale_factor The modes available for resizing are: nearest, linear (3D-only), bilinear, bicubic (4D-only), trilinear (5D-only), area

Parameters
  • data (Tensor) – input tensor of shape batch x channels x height x width x [depth]

  • size (Union[int, Sequence[int], None]) – spatial output size (excluding batch size and number of channels)

  • scale_factor (Union[float, Sequence[float], None]) – multiplier for spatial size

  • mode (str) – one of nearest, linear, bilinear, bicubic, trilinear, area (for more inforamtion see torch.nn.functional.interpolate())

  • align_corners (Optional[bool]) – input and output tensors are aligned by the center points of their corners pixels, preserving the values at the corner pixels.

  • preserve_range (bool) – output tensor has same range as input tensor

Returns

interpolated tensor

Return type

torch.Tensor

mirror

rising.transforms.functional.spatial.mirror(data, dims)[source][source]

Mirror data at dims

Parameters
Returns

tensor with mirrored dimensions

Return type

torch.Tensor

rot90

rising.transforms.functional.spatial.rot90(data, k, dims)[source][source]

Rotate 90 degrees around dims

Parameters
Returns

tensor with mirrored dimensions

Return type

torch.Tensor

resize_native

rising.transforms.functional.spatial.resize_native(data, size=None, scale_factor=None, mode='nearest', align_corners=None, preserve_range=False)[source][source]

Down/up-sample sample to either the given size or the given scale_factor The modes available for resizing are: nearest, linear (3D-only), bilinear, bicubic (4D-only), trilinear (5D-only), area

Parameters
  • data (Tensor) – input tensor of shape batch x channels x height x width x [depth]

  • size (Union[int, Sequence[int], None]) – spatial output size (excluding batch size and number of channels)

  • scale_factor (Union[float, Sequence[float], None]) – multiplier for spatial size

  • mode (str) – one of nearest, linear, bilinear, bicubic, trilinear, area (for more inforamtion see torch.nn.functional.interpolate())

  • align_corners (Optional[bool]) – input and output tensors are aligned by the center points of their corners pixels, preserving the values at the corner pixels.

  • preserve_range (bool) – output tensor has same range as input tensor

Returns

interpolated tensor

Return type

torch.Tensor

Tensor Transforms

rising.transforms.functional.tensor.tensor_op(data, fn, *args, **kwargs)[source][source]

Invokes a function form a tensor

Parameters
  • data (Union[Tensor, List[Tensor], Tuple[Tensor], Mapping[Hashable, Tensor]]) – data which should be pushed to device. Sequence and mapping items are mapping individually to gpu

  • fn (str) – tensor function

  • *args – positional arguments passed to tensor function

  • **kwargs – keyword arguments passed to tensor function

Returns

data which was pushed to device

Return type

Union[torch.Tensor, Sequence, Mapping]

rising.transforms.functional.tensor.to_device_dtype(data, dtype=None, device=None, **kwargs)[source][source]

Pushes data to device

Parameters
Returns

data which was pushed to device

Return type

Union[torch.Tensor, Sequence, Mapping]

tensor_op

rising.transforms.functional.tensor.tensor_op(data, fn, *args, **kwargs)[source][source]

Invokes a function form a tensor

Parameters
  • data (Union[Tensor, List[Tensor], Tuple[Tensor], Mapping[Hashable, Tensor]]) – data which should be pushed to device. Sequence and mapping items are mapping individually to gpu

  • fn (str) – tensor function

  • *args – positional arguments passed to tensor function

  • **kwargs – keyword arguments passed to tensor function

Returns

data which was pushed to device

Return type

Union[torch.Tensor, Sequence, Mapping]

to_device_dtype

rising.transforms.functional.tensor.to_device_dtype(data, dtype=None, device=None, **kwargs)[source][source]

Pushes data to device

Parameters
Returns

data which was pushed to device

Return type

Union[torch.Tensor, Sequence, Mapping]

Utility Transforms

rising.transforms.functional.utility.box_to_seg(boxes, shape=None, dtype=None, device=None, out=None)[source][source]

Convert a sequence of bounding boxes to a segmentation

Parameters
  • boxes (Sequence[Sequence[int]]) – sequence of bounding boxes encoded as (dim0_min, dim1_min, dim0_max, dim1_max, [dim2_min, dim2_max]). Supported bounding boxes for 2D (4 entries per box) and 3d (6 entries per box)

  • shape (Optional[Sequence[int]]) – if out is not provided, shape of output tensor must be specified

  • dtype (Union[dtype, str, None]) – if out is not provided, dtype of output tensor must be specified

  • device (Union[device, str, None]) – if out is not provided, device of output tensor must be specified

  • out (Optional[Tensor]) – if not None, the segmentation will be saved inside this tensor

Returns

bounding boxes encoded as a segmentation

Return type

torch.Tensor

rising.transforms.functional.utility.seg_to_box(seg, dim)[source][source]

Convert instance segmentation to bounding boxes

Parameters
  • seg (Tensor) – segmentation of individual classes (index should start from one and be continuous)

  • dim (int) – number of spatial dimensions

Returns

list of bounding boxes tuple with classes for

bounding boxes

Return type

list

rising.transforms.functional.utility.instance_to_semantic(instance, cls)[source][source]

Convert an instance segmentation to a semantic segmentation

Parameters
  • instance (Tensor) – instance segmentation of objects (objects need to start from 1, 0 background)

  • cls (Sequence[int]) – mapping from indices from instance segmentation to real classes.

Returns

semantic segmentation

Return type

torch.Tensor

Warning

instance needs to encode objects starting from 1 and the indices need to be continuous (0 is interpreted as background)

rising.transforms.functional.utility.pop_keys(data, keys, return_popped=False)[source][source]

Pops keys from a given data dict

Parameters
  • data (dict) – the dictionary to pop the keys from

  • keys (Union[Callable, Sequence]) – if callable it must return a boolean for each key indicating whether it should be popped from the dict. if sequence of strings, the strings shall be the keys to be popped

  • return_popped – whether to also return the popped values

  • (default – False)

Returns

the data without the popped values dict: the popped values; only if :attr`return_popped` is True

Return type

dict

rising.transforms.functional.utility.filter_keys(data, keys, return_popped=False)[source][source]

Filters keys from a given data dict

Parameters
  • data (dict) – the dictionary to pop the keys from

  • keys (Union[Callable, Sequence]) – if callable it must return a boolean for each key indicating whether it should be retained in the dict. if sequence of strings, the strings shall be the keys to be retained

  • return_popped – whether to also return the popped values (default: False)

Returns

the data without the popped values dict: the popped values; only if return_popped is True

Return type

dict

box_to_seg

rising.transforms.functional.utility.box_to_seg(boxes, shape=None, dtype=None, device=None, out=None)[source][source]

Convert a sequence of bounding boxes to a segmentation

Parameters
  • boxes (Sequence[Sequence[int]]) – sequence of bounding boxes encoded as (dim0_min, dim1_min, dim0_max, dim1_max, [dim2_min, dim2_max]). Supported bounding boxes for 2D (4 entries per box) and 3d (6 entries per box)

  • shape (Optional[Sequence[int]]) – if out is not provided, shape of output tensor must be specified

  • dtype (Union[dtype, str, None]) – if out is not provided, dtype of output tensor must be specified

  • device (Union[device, str, None]) – if out is not provided, device of output tensor must be specified

  • out (Optional[Tensor]) – if not None, the segmentation will be saved inside this tensor

Returns

bounding boxes encoded as a segmentation

Return type

torch.Tensor

seg_to_box

rising.transforms.functional.utility.seg_to_box(seg, dim)[source][source]

Convert instance segmentation to bounding boxes

Parameters
  • seg (Tensor) – segmentation of individual classes (index should start from one and be continuous)

  • dim (int) – number of spatial dimensions

Returns

list of bounding boxes tuple with classes for

bounding boxes

Return type

list

instance_to_semantic

rising.transforms.functional.utility.instance_to_semantic(instance, cls)[source][source]

Convert an instance segmentation to a semantic segmentation

Parameters
  • instance (Tensor) – instance segmentation of objects (objects need to start from 1, 0 background)

  • cls (Sequence[int]) – mapping from indices from instance segmentation to real classes.

Returns

semantic segmentation

Return type

torch.Tensor

Warning

instance needs to encode objects starting from 1 and the indices need to be continuous (0 is interpreted as background)

pop_keys

rising.transforms.functional.utility.pop_keys(data, keys, return_popped=False)[source][source]

Pops keys from a given data dict

Parameters
  • data (dict) – the dictionary to pop the keys from

  • keys (Union[Callable, Sequence]) – if callable it must return a boolean for each key indicating whether it should be popped from the dict. if sequence of strings, the strings shall be the keys to be popped

  • return_popped – whether to also return the popped values

  • (default – False)

Returns

the data without the popped values dict: the popped values; only if :attr`return_popped` is True

Return type

dict

filter_keys

rising.transforms.functional.utility.filter_keys(data, keys, return_popped=False)[source][source]

Filters keys from a given data dict

Parameters
  • data (dict) – the dictionary to pop the keys from

  • keys (Union[Callable, Sequence]) – if callable it must return a boolean for each key indicating whether it should be retained in the dict. if sequence of strings, the strings shall be the keys to be retained

  • return_popped – whether to also return the popped values (default: False)

Returns

the data without the popped values dict: the popped values; only if return_popped is True

Return type

dict


© Copyright Copyright (c) 2019-2020, Justus Schock, Michael Baumgartner.. Revision 871c839e.

Read the Docs v: v0.2.0
Versions
latest
stable
v0.2.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.