Modules

Image augmentation

class deoxys_image.augmentation.ImageAugmentation(rank, rotation_range=0, rotation_axis=0, rotation_chance=0.2, zoom_range=1, zoom_chance=0.2, shift_range=None, shift_chance=0.1, flip_axis=None, brightness_range=1, brightness_channel=None, brightness_chance=0.1, contrast_range=1, contrast_channel=None, contrast_chance=0.1, noise_variance=0, noise_channel=None, noise_chance=0.1, blur_range=0, blur_channel=None, blur_chance=0.1, fill_mode='constant', cval=0, multiprocessing=1)[source]

Apply transformation in 2d and 3d image (and mask label) for augmentation

Parameters
  • rank (int) – rank of a single image (2d: 3, 3d: 4)

  • rotation_range (int, optional) – range of the angle rotation, in degree, by default 0 (no rotation)

  • rotation_axis (int, optional) – the axis of one image to apply rotation, by default 0

  • rotation_chance (float, optional) – probability to apply rotation transformation to an image, by default 0.2

  • zoom_range (float, list, tuple optional) – the range of zooming, zooming out when the number is less than 1, and zoom in (enlarge) when the number is larger than 1. If a float, then it is the range between that number and 1, by default 1 (no zooming)

  • zoom_chance (float, optional) – probability to apply zoom transformation to an image, by default 0.2

  • shift_range (tuple or list, optional) – the range of translation in each axis, by default None (no shifts)

  • shift_chance (float, optional) – probability to apply translation transformation to an image, by default 0.1

  • flip_axis (int, tuple, list, optional) – flip by one or more axis (in the single image), by default None (no flipping)

  • brightness_range (float, tuple, list, optional) –

    range of the brightness portion, based on the max intensity value of each channel. For example, when the max intensity value of one channel is 1.0, and the brightness is chaned by 1.2, then every pixel in that channel will increase the intensity value by 0.2.

    \[0.2 = 1.0 \cdot (1.2 - 1)\]

    By default 1 (no changes in brightness)

  • brightness_channel (int, tuple, list, optional) – the channel(s) to apply changes in brightness, by default None (apply to all channels)

  • brightness_chance (float, optional) – probability to apply brightness change transform to an image, by default 0.1

  • contrast_range (float, tuple, list, optional) – range of the contrast portion, (the histogram range is scaled up or down). By default 1 (no changes in contrast)

  • contrast_channel (int, tuple, list, optional) – the channel(s) to apply changes in contrast, by default None (apply to all channels)

  • contrast_chance (float, optional) – probability to apply contrast change transform to an image, by default 0.1

  • noise_variance (int, tuple, list, optional) – range of the noise variance when adding Gaussian noise to the image, by default 0 (no adding noise)

  • noise_channel (int, tuple, list, optional) – the channel(s) to apply Gaussian noise, by default None (apply to all channels)

  • noise_chance (float, optional) – probability to apply gaussian noise to an image, by default 0.1

  • blur_range (int, tuple, list, optional) – range of the blur sigma when applying the Gaussian filter to the image, by default 0 (no blur)

  • blur_channel (int, tuple, list, optional) – the channel(s) to apply Gaussian blur, by default None (apply to all channels)

  • blur_chance (float, optional) – probability to apply gaussian blur to an image, by default 0.1

  • fill_mode (str, optional) – the fill mode in affine transformation (rotation, zooming, shifting / translation), one of {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, by default ‘constant’

  • cval (int, optional) – When rotation, or zooming, or shifting is applied to the image, cval is the value to fill past edges of input if fill_mode is ‘constant’. By default 0

transform(images, targets=None)[source]

Apply augmentation to a batch of images

Parameters
  • images (np.array) – the image batch

  • targets (np.array, optional) – the target batch, by default None

Returns

the transformed images batch (and target)

Return type

np.array

deoxys_image.augmentation.apply_augmentation(images, targets=None, rotation_range=0, rotation_axis=0, rotation_chance=0.2, zoom_range=1, zoom_chance=0.2, shift_range=None, shift_chance=0.1, flip_axis=None, brightness_range=1, brightness_channel=None, brightness_chance=0.1, contrast_range=1, contrast_channel=None, contrast_chance=0.1, noise_variance=0, noise_channel=None, noise_chance=0.1, blur_range=0, blur_channel=None, blur_chance=0.1, fill_mode='constant', cval=0)[source]
deoxys_image.augmentation.get_random_affine_params(rotation_range, rotation_chance, zoom_range, zoom_chance, shift_range, shift_chance)[source]
deoxys_image.augmentation.get_range_affine_transform(rank, rotation_range, zoom_range, shift_range)[source]
deoxys_image.augmentation.get_range_value(value, default_val=1)[source]

Image Transformation

Affine Transformation

deoxys_image.affine_transform.affine_transform_matrix(rotation_axis=2, theta=0, rank=3, zoom_factor=1, **kwargs)[source]
deoxys_image.affine_transform.apply_affine_transform(image, mode='constant', cval=0, **kwargs)[source]
deoxys_image.affine_transform.apply_flip(image, axis)[source]
deoxys_image.affine_transform.get_matrix_n_offset(transform_matrix, image_shape, shift)[source]
deoxys_image.affine_transform.get_rotation_matrix(rotation_axis, theta, rank=3)[source]
\[\begin{split}\begin{pmatrix} \cos(\frac{x'}{x})&\cos(\frac{y'}{x})&\cos(\frac{z'}{x})\\ \cos(\frac{x'}{y})&\cos(\frac{y'}{y})&\cos(\frac{z'}{y})\\ \cos(\frac{x'}{z})&\cos(\frac{y'}{z})&\cos(\frac{z'}{z}) \end{pmatrix}\end{split}\]

x, y, z are axis 2, 0, 1 respectively

Parameters
  • rotation_axis ([type]) – [description]

  • theta ([type]) – [description]

Returns

[description]

Return type

[type]

deoxys_image.affine_transform.get_shift_matrix(shift, rank=3)[source]

Return the shift matrix in affine transform

\[\begin{split}\begin{pmatrix}1&0&offset_x\\ 0&1&offset_y\\ 0&0&1 \end{pmatrix}\end{split}\]
Parameters
  • shift (int,) – number of pixel to shift

  • rank (int, optional) – the rank of the matrix, by default 3

Returns

the shift matrix

Return type

np.array

deoxys_image.affine_transform.get_zoom_matrix(zoom_factor, rank=3)[source]
deoxys_image.affine_transform.get_zoom_matrix_from_factors(zoom_factor, rank=3)[source]
deoxys_image.affine_transform.transform_matrix_offset_center(matrix, width, height, depth=None)[source]

Point operation

deoxys_image.point_operation.apply_gaussian_noise(images, noise_var=0.1, channel=None)[source]

Apply gaussian noise of variance noise_var

Parameters
  • images (np.array) – images

  • noise_var (float, optional) – the variance of the noise value

  • channel (int or list, optional) – channel or channels to be added with random noise, by default None, which means all channels are added with random noise

Returns

images with noise

Return type

np.array

deoxys_image.point_operation.apply_random_brightness(images, low=0.7, high=1.3, channel=None)[source]
deoxys_image.point_operation.apply_random_contrast(images, low=0.6, high=1.4, channel=None)[source]
deoxys_image.point_operation.apply_random_gaussian_noise(images, variance=None, channel=None)[source]

Apply gaussian noise with random noise variance in the range of variance

Parameters
  • images (np.array) – images

  • variance (tuple or float, optional) – range of the noise variance, by default (0, 0.1)

  • channel (int or list, optional) – channel or channels to be added with random noise, by default None, which means all channels are added with random noise

deoxys_image.point_operation.change_brightness(image, factor, channel=None)[source]

Change brightness of an images by adding a constant to all pixels in the image so that max(new_image) = factor * max(image)

Parameters
  • image (np.array) – the image

  • factor (float) – change factor for brightness. Factor > 1 means the image will get brighter

  • channel (int or list, optional) – channel or channels to be adjusted, by default None, which means all channels will be adjusted

Returns

image with changes in brightness

Return type

np.array

deoxys_image.point_operation.change_contrast(image, factor, channel=None)[source]

Change contrast of an images by a factor

Parameters
  • image (np.array) – the image

  • factor (float) – change factor for contrast. Factor > 1 increases the contrast

  • channel (int or list, optional) – channel or channels to be adjusted, by default None, which means all channels will be adjusted

Returns

image with changes in contrast

Return type

np.array

deoxys_image.point_operation.gaussian_noise(image, noise_var=0.1, channel=None)[source]

Apply gaussian noise of variance noise_var to a single image

Parameters
  • image (np.array) – the image

  • noise_var (float, optional) – the variance of the noise value, by default 0.1

  • channel (int or list, optional) – channel or channels to be added with random noise, by default None, which means all channels are added with random noise

Returns

images with noise

Return type

np.array

deoxys_image.point_operation.normalize(images, vmin=None, vmax=None)[source]

Convolutional operation

deoxys_image.filters.apply_random_gaussian_blur(images, low=0.5, high=1.5, channel=None)[source]
deoxys_image.filters.gaussian_blur(image, sigma=0.4, channel=None)[source]

Indices and tables