Random Smooth Grayvalue Transformation

Installation

The package is available for Python 2.7+ and 3.x. There are no dependencies other than numpy.

Installation is straightforward via PyPI:

pip install rsgt

Augmentation

rsgt.augmentation.random_smooth_grayvalue_transform(image, n_sinusoids=4, min_frequency=0.2, max_freqency=1.6, dtype='float32', min_max_val=None)

Applies random smooth gray value transformations to a numpy array.

The original array is not changed, a new array is returned. The input array is expected to have integer values, the returned array will have values in the range [0,1] and the specified dtype, which should therefore be a floating point type.

The shape of the sin terms can be restricted through the two min/max frequency parameters and the number of sin terms in the transformation function. These define how “bouncy” the final transformation function will be (larger values = more ups and downs in the function).

The range of input values can be optionally specified, otherwise the min and max values of the input image are used. In cases where the input value range is known, it makes sense to use this parameter, e.g., when using CT data.

Parameters
  • image – numpy array, or anything convertable into a numpy array

  • n_sinusoids – int, the number of sinusoidal functions that will make up the transformation function

  • min_frequency – float, minimal frequency of the randomly generated sin functions

  • max_freqency – float, maximal frequency of the randomly generated sin functions

  • dtype – Target dtype, should be a floating point type because output values are in [0,1]

  • min_max_val – Tuple of two values (min/max), or None; range of input values

Returns

numpy array with specific dtype and values in the range [0, 1]

Normalization

rsgt.normalization.normalize_ct_scan(image, dtype='float32')

Normalizes a CT scan from the range of Hounsfield Units [-1000, ~3000) to the range [0,1]

Parameters
  • image – numpy array

  • dtype – output dtype, should be a floating point type

Returns

numpy array

rsgt.normalization.normalize_mr_scan(image, dtype='float32')

Normalizes an MR scan by scaling the values in the [5%,95%] percentiles to the range [0,1]

Parameters
  • image – numpy array

  • dtype – output dtype, should be a floating point type

Returns

numpy array