Dicom

Transforms

class NPSNoise(magnitude: int = (50, 150), sample_tube_current: bool = False, always_apply: bool = False, p: float = 1.0)[source]

Bases: ImageOnlyTransform

Insert random image noise based on the (0018,1210) Convolution Kernel type of the dicom header.

Parameters:
  • magnitude ((int, int) or int) – scaling magnitude range of noise. If magnitude is a single integer value, the range will be (1, magnitude). Default: (50, 150).

  • sample_tube_current (bool) – If True, then magnitude is ignored and the magnitude is sampled from the range (0, 500 - (0018,1151) X-Ray Tube Current)

  • always_apply (bool) – whether to always apply the transformation. Default: False

  • p (float) – probability of applying the transform. Default: 1.

Targets:

image, dicom

Image types:

int16

Note

The current supported kernel types include Siemens kernels: b10f, b20f, b22f, b26f, b30f, b31f, b35f, b36f, b40f, b41f, b43f, b45f, b46f, b50f, b60f, b70f, b75f, b80f, and GE kernels: bone, boneplus, chest, detail, edge, lung, soft, standard

Note

This transformation requires the use a DICOM header object. See dicaugment.read_dcm_image() for full syntax. .. code-block:: python

import dicaugment as dca image, dicom = dca.read_dcm_image(path=’path/to/dcm/folder/’, return_header=True) aug = dca.Compose([dca.NPSNoise()]) result = aug(image=image, dicom=dicom)

apply(img: ndarray, kernel: str = 'STANDARD', x_step: float = 0.5, y_step: float = 0.5, magnitude: int = 1, **params)[source]

Applies the transformation to the image

get_params() Dict[source]

Returns parameters needed for the apply methods

get_params_dependent_on_targets(params: Dict[str, Any]) Dict[str, Any][source]

Returns additional parameters needed for the apply methods that depend on a target (e.g. apply_to_bboxes method expects image size)

get_transform_init_args_names() Tuple[str, ...][source]

Returns initialization argument names. (e.g. Transform(arg1 = 1, arg2 = 2) -> (‘arg1’, ‘arg2’))

property targets_as_params

Returns a list of target names (e.g. ‘image’) that are needed as a parameter input to other apply methods (e.g. apply_to_bboxes(…, image = image))

class RescaleSlopeIntercept(always_apply: bool = False, p: float = 1.0)[source]

Bases: ImageOnlyTransform

Harmonizes the pixel intensity values using the (0028, 1053) Rescale Slope and (0028, 1052) Rescale Intercept values from a dicom header. This will return the image with data type np.int16.

Parameters:
  • always_apply (bool) – whether to always apply the transformation. Default: False

  • p (float) – probability of applying the transform. Default: 1.

Targets:

image, dicom

Image types:

int16, uint16

Note

This transformation requires the use a DICOM header object. See dicaugment.read_dcm_image() for full syntax. .. code-block:: python

import dicaugment as dca image, dicom = dca.read_dcm_image(path=’path/to/dcm/folder/’, return_header=True) aug = dca.Compose([dca.RescaleSlopeIntercept()]) result = aug(image=image, dicom=dicom)

apply(img: ndarray, slope: float, intercept: float, **params) ndarray[source]

Applies the transformation to the image

apply_to_dicom(dicom, **params)[source]

Applies the augmentation to a dicom type

get_params_dependent_on_targets(params)[source]

Returns additional parameters needed for the apply methods that depend on a target (e.g. apply_to_bboxes method expects image size)

get_transform_init_args_names() Tuple[str, ...][source]

Returns initialization argument names. (e.g. Transform(arg1 = 1, arg2 = 2) -> (‘arg1’, ‘arg2’))

property targets: Dict[str, Callable]

Returns the mapping of target to applicable apply method. (e.g. {‘image’: self.apply, ‘bboxes’, self.apply_to_bboxes})

property targets_as_params

Returns a list of target names (e.g. ‘image’) that are needed as a parameter input to other apply methods (e.g. apply_to_bboxes(…, image = image))

class SetPixelSpacing(space_x: float = 1.0, space_y: float = 1.0, interpolation=1, always_apply=False, p=1)[source]

Bases: DualTransform

Harmonizes spatial pixel spacing such that the (0028, 0030) Pixel Spacing values of the dicom header are equal to space_x and space_y respectively

Parameters:
  • space_x (float) – desired pixel spacing in the width dimension. Default: 1.0

  • space_y (float) – desired pixel spacing in the height dimension. Default: 1.0

  • interpolation (int) – scipy interpolation method (e.g. dicaugment.INTER_NEAREST). Default: dicaugment.INTER_LINEAR

  • always_apply (bool) – whether to always apply the transformation. Default: False

  • p (float) – probability of applying the transform. Default: 1.

Targets:

image, dicom, mask, bboxes, keypoints

Image types:

uint8, uint16, int16, float32

Note

This transformation requires the use a DICOM header object. See dicaugment.read_dcm_image() for full syntax.

Example

import dicaugment as dca
image, dicom = dca.read_dcm_image(path='path/to/dcm/folder/', return_header=True)
aug = dca.Compose([dca.SetPixelSpacing(space_x=0.5, space_y=0.5)])
result = aug(image=image, dicom=dicom)
apply(img: ndarray, interpolation: int = 1, scale_x: float = 1.0, scale_y: float = 1.0, **params) ndarray[source]

Applies the transformation to the image

apply_to_bbox(bbox: Tuple[float, float, float, float], **params) Tuple[float, float, float, float][source]

Applies the transformation to a bbox. Bounding box coordinates are scale invariant

apply_to_dicom(dicom: Dict[str, Any], scale_x: float, scale_y: float, **params) Dict[str, Any][source]

Applies the augmentation to a dicom type

apply_to_keypoint(keypoint: Tuple[float, float, float, float], scale_x: float, scale_y: float, scale_z: float, **params) Tuple[float, float, float, float][source]

Applies the transformation to a keypoint

get_params_dependent_on_targets(params: Dict[str, Any]) Dict[str, Any][source]

Returns additional parameters needed for the apply methods that depend on a target (e.g. apply_to_bboxes method expects image size)

get_transform_init_args_names() Tuple[str][source]

Returns initialization argument names. (e.g. Transform(arg1 = 1, arg2 = 2) -> (‘arg1’, ‘arg2’))

property targets_as_params: List[str]

Returns a list of target names (e.g. ‘image’) that are needed as a parameter input to other apply methods (e.g. apply_to_bboxes(…, image = image))

Functional

dicom_scale(dicom: Dict[str, Any], scale_x: float, scale_y: float) Dict[str, Any][source]

Scales the PixelSpacing of a Dicom Object

Parameters:
  • dicom (DicomType) – a Dicom object

  • scale_x (float) – factor to scale the PixelSpacing in the x dimension

  • scale_y (float) – factor to scale the PixelSpacing in the y dimension

rescale_slope_intercept(img: ndarray, slope: float, intercept: float) ndarray[source]

Scales and offsets an image’s pixel values using the formula img = (img * slope) + intercept

Parameters:
  • img (np.ndarray) – an image

  • slope (float) – the factor to scale the pixel values by

  • intercept (float) – the value to offset the pixel values by

reset_dicom_slope_intercept(dicom: Dict[str, Any]) Dict[str, Any][source]

Sets the RescaleSlope and RescaleIntercept keys of a Dicom Object to 1 and 0, respectively.

Parameters:

dicom (DicomType) – a Dicom object

transpose_dicom(dicom: Dict[str, Any]) Dict[str, Any][source]

Transposes the PixelSpacing of a Dicom Object

Parameters:

dicom (DicomType) – a Dicom object