siemens

Module contents

Utilities for handling Siemens DICOM data.

Subpackages

Submodules

dicom_parser.utils.siemens.mosaic module

Definition of the Mosaic class that decodes the 2D encoding of 3D volumes used by Siemens. For more information read this NiBabel article or see pages 10-12 in here.

class dicom_parser.utils.siemens.mosaic.Mosaic(mosaic_array: numpy.ndarray, header: dicom_parser.header.Header)

Bases: object

A Siemens mosaic of 2D images representing a single volume.

CSA_ASCII_HEADER_KEY: str = 'MrPhoenixProtocol'
CSA_ASCII_SLICE_ARRAY_KEY: str = 'sSliceArray'
CSA_SERIES_INFO_KEY: str = 'CSASeriesHeaderInfo'
fold() numpy.ndarray

Folds the 2D mosaic to become a 3D volume.

Returns

3D volume

Return type

np.ndarray

get_image_position(iop: numpy.ndarray) Tuple[float, float, float]

Returns a fixed Image Position (Patient) header field value.

Parameters

iop (np.ndarray) – Image Orientation (Patient) header field value

References

Returns

Image Position (Patient) header field value

Return type

Tuple[float, float, float]

get_image_shape() Tuple[int, int]

Returns the 2D shape of a single image within the mosaic.

Returns

Single image shape

Return type

Tuple[int, int]

get_mosaic_dimensions() tuple

Returns the number of rows and columns that make up the mosaic.

Returns

n_rows, n_columns

Return type

tuple

get_n_images() int

Returns the number of images encoded in the mosaic.

Returns

Number of images encoded in mosaic

Return type

int

get_tile(i_row: int, i_column: int) numpy.ndarray

Cut out a tile of the mosaic by row and column indices.

Parameters
  • i_row (int) – Row index

  • i_column (int) – Column index

Returns

A single tile at the (i_row, i_column) position

Return type

np.ndarray

get_tiles() list

Cuts out the tiles (2D slices) from the mosaic.

Returns

Tiles collected by row

Return type

list

get_volume_shape() Tuple[float, float, float]

Returns the dimensions of the volume that will be created.

Returns

Volume shape

Return type

Tuple[float, float, float]

tiles_to_volume(tiles: list) numpy.ndarray

Transforms a list of tiles to a correctly oriented volume.

Parameters

tiles (list) – List of 2D slices as parsed from the mosaic

Returns

Orientation-fixed volume

Return type

np.ndarray

dicom_parser.utils.siemens.private_tags module

Siemens specific private tags they may not be accessible by keyword using pydicom.

dicom_parser.utils.siemens.private_tags.B_MATRIX_INDICES = array([0, 1, 2, 1, 3, 4, 2, 4, 5])

The raw (6, 1) vector returned represents the upper triangle of a symmetric B matrix.

dicom_parser.utils.siemens.private_tags.b_matrix_to_q_vector(b_matrix: numpy.ndarray, tol: Optional[float] = None) numpy.ndarray

Estimate q-vector from B matrix.

References

Parameters

b_matrix (np.ndarray (3, 3)) – B matrix

Returns

q-vector

Return type

np.ndarray

dicom_parser.utils.siemens.private_tags.nearest_pos_semi_def(b_matrix: numpy.ndarray)

Least squares positive semi-definite tensor estimation.

References

Parameters

b_matrix (np.ndrray) – B matrix

Returns

npds – Estimated nearest positive semi-definite array to matrix B

Return type

(3,3) array

Examples

>>> B = np.diag([1, 1, -1])
>>> nearest_pos_semi_def(B)
array([[0.75, 0.  , 0.  ],
       [0.  , 0.75, 0.  ],
       [0.  , 0.  , 0.  ]])
dicom_parser.utils.siemens.private_tags.parse_siemens_b_matrix(value: Union[float, bytes]) numpy.ndarray

Parses the Siemens B matrix header field value.

Parameters

value (Union[float, bytes]) – Raw B matrix header field value

Returns

Parsed B matrix

Return type

np.ndarray

dicom_parser.utils.siemens.private_tags.parse_siemens_b_matrix_multiple(value: List[float])

Parses the Siemens B matrix header field value.

Parameters

value (List[float]) – Raw B matrix header field value

Returns

Parsed B matrix

Return type

np.ndarray

dicom_parser.utils.siemens.private_tags.parse_siemens_bandwith_per_pixel_phase_encode(value: Union[bytes, float]) float

Parses the BandwidthPerPixelPhaseEncode (0019, 1028) private tag value.

Parameters

value (bytes) – Raw element value

Returns

Parsed value

Return type

float

Raises

TypeError – Bad value type

dicom_parser.utils.siemens.private_tags.parse_siemens_csa_header(value: bytes) dict

Parses a Siemens CSA header to a dictionary using the CsaHeader class.

Parameters

value (bytes) – Raw CSA header

Returns

Parsed CSA header information

Return type

dict

dicom_parser.utils.siemens.private_tags.parse_siemens_gradient_direction(value: Union[bytes, float]) Union[float, Tuple[float]]

Parses a SIEMENS MR image’s B-vector as represented in the private (0019, 100E) DiffusionGradientDirection DICOM tag.

Parameters

value (Union[bytes, float]) – SIEMENS private DiffusionGradientDirection data element.

Returns

Gradient directions (B-vector)

Return type

Union[float, Tuple[float]]

dicom_parser.utils.siemens.private_tags.parse_siemens_number_of_slices_in_mosaic(value: Union[bytes, int]) int

Parses the NumberOfImagesInMosaic (0019, 100a) private tag value.

Parameters

value (Union[bytes, int]) – Raw element value

Returns

Parsed number of images in mosaic value

Return type

int

Raises

TypeError – Bad value type

dicom_parser.utils.siemens.private_tags.parse_siemens_slice_timing(value: Union[bytes, float]) Union[float, Tuple[float]]

Parses a SIEMENS MR image’s slice timing as saved in the private (0019, 1029) MosaicRefAcqTimes tag to a list of floats representing slice times in milliseconds.

Parameters

value (bytes or float) – SIEMENS private MosaicRefAcqTimes data element

Returns

Slice times in milliseconds

Return type

Union[float, Tuple[float]]