multi_frame

Module contents

Multi-frame image parsing functionality module.

Submodules

dicom_parser.utils.multi_frame.functional_groups

Definition of the FunctionalGroups class.

class dicom_parser.utils.multi_frame.functional_groups.FunctionalGroups(frame_header: dicom_parser.header.Header)

Bases: object

Represents a single frame’s functional groups sequence in a multi-frame encoded acquisition.

property appendix_flag: bool

Returns whether the header information includes a tag that would flag it as containing derivatives as appended frames.

Returns

Whether the functional groups header information contains an appendix flag or not

Return type

bool

check_derived() bool

Checks whether this frame is a derivative or a part of the image.

See also

Returns

Whether this frame is a derived frame or not

Return type

bool

get_content_sequence() dicom_parser.header.Header

Returns a single frame’s functional groups sequence’s frame content information, or None for shared functional groups.

Returns

Frame content sequence

Return type

Header

Raises

DicomParsingError – Failed to read frame content sequence

get_diffusion_directionality() str

Returns the diffusion directionality from the MR diffusion sequence.

Returns

Diffusion directionality

Return type

str

get_diffusion_sequence() dicom_parser.header.Header

Returns the MR diffusion sequence.

Returns

MR difussion sequence

Return type

Header

Raises

DicomParsingError – Failed to read MR diffusion sequence

get_index() Tuple[int, int, int]

Reads the group’s index from the header information.

Returns

Frame index

Return type

Tuple[int, int, int]

Raises

DicomParsingError – Missing header information

get_pixel_measures() dicom_parser.header.Header

Returns a functional groups sequence’s pixel measures, which are used to determine voxel sizes.

Returns

Pixel measures

Return type

Header

Raises

DicomParsingError – Failed to read pixel measures

get_pixel_value_transformations() dicom_parser.header.Header

Returns the pixel value transformations that are required for rescaling.

Returns

Pixel value transformations

Return type

Header

Raises

DicomParsingError – Missing pixel value transformations

get_plane_orientation() dicom_parser.header.Header

Returns the plane orientation sequence.

Returns

Plane orientation sequence

Return type

Header

Raises

DicomParsingError – Missing plane orientation sequence

get_plane_position() dicom_parser.header.Header

Returns the plane position sequence.

Returns

Plane position sequence

Return type

Header

Raises

DicomParsingError – Missing plane position sequence

get_stack_id() str

Reads a single frame’s stack ID from its associated functional groups header information.

Returns

Stack ID

Return type

str

Raises

DicomParsingError – Missing header information

property is_appendix: bool

Checks whether this frame is a derivative (appended to the image) or a part of the image.

See also

Returns

Whether this frame is a derived frame or not

Return type

bool

dicom_parser.utils.multi_frame.functional_groups.PHILLIPS_APPENDIX_FLAG: Tuple[float, float] = (24, 37143)

Phillips derived data appendix data element tag.

dicom_parser.utils.multi_frame.messages module

Messages for the dicom_parser.utils.multi_frame module.

dicom_parser.utils.multi_frame.messages.AMBIGUOUS_N_FRAMES: str = 'Ambiguous multi-frame number of frames value! Expected {header_n_frames} frames, but only {n_frame_info} have functional groups information included.'

Ambiguous number of frames.

dicom_parser.utils.multi_frame.messages.EMPTY_SHARED_FUNCTIONAL_GROUPS: str = 'Shared functional groups sequence is empty! Faild to parse multi-frame image pixel array.'

Message to display if the shared functional groups sequence is empty.

dicom_parser.utils.multi_frame.messages.INVALID_DIFFUSION_SEQUENCE: str = 'Phillips multi-frame encoded diffusion sequence missing MRDiffusionSequence header information.'

Exception message for invalid Phillips appended derived framed within a multi-frame.

dicom_parser.utils.multi_frame.messages.MISSING_CONTENT_SEQUENCE: str = 'Missing content sequence! Failed to parse multi-frame array pixel array.'

Message to display if a multi-frame image’s frame has no content sequence.

dicom_parser.utils.multi_frame.messages.MISSING_DERIVED_INDICES: str = 'Missing derived volume dimension index pointers! Cannot parse multi-frame image data with confidence.'

Missing derived volume dimension index pointers.

dicom_parser.utils.multi_frame.messages.MISSING_DIMENSION_INDEX_POINTERS: str = 'Failed to read dimension index pointers for multi-frame image.\nRaised exception:\n{exception}'

Missing dimension index pointers in image header information.

dicom_parser.utils.multi_frame.messages.MISSING_FRAME_INDEX: str = 'Failed to read frame indices for a multi-frame encoded image.'

Missing index in frame functional groups information.

dicom_parser.utils.multi_frame.messages.MISSING_FUNCTIONAL_GROUPS: str = 'Missing {sequence_type} functional groups sequence! Multi-frame image parsing is not possible.'

Missing per frame functional groups sequences.

dicom_parser.utils.multi_frame.messages.MISSING_IMAGE_POSITION: str = 'Image position header information could not be determined for multi-frame image.'

Message to display if image position could not be read.

dicom_parser.utils.multi_frame.messages.MISSING_IMAGE_SHAPE: str = 'Missing image shape! Failed to parse multi-frame array pixel array.'

Message to display of the image shape could not be determined, causing a pixel array read failure.

dicom_parser.utils.multi_frame.messages.MISSING_IOP: str = 'Image Orientation (Patient) header information is missing! Failed to parse multi-frame image data.'

Message to display if the image orientation (patient) header information is missing.

dicom_parser.utils.multi_frame.messages.MISSING_PIXEL_MEASURES: str = 'Missing pixel measures sequence! Voxel sizes could not be determined for multi-frame image.'

Message to display if the voxel sizes could not be read from the header due to a missing pixel measures sequence.

dicom_parser.utils.multi_frame.messages.MISSING_PIXEL_SPACING: str = 'Pixel spacing could not be read from multi-frame image pixel measures!'

Message to display if pixel spacing could not be read from pixel measures.

dicom_parser.utils.multi_frame.messages.MISSING_PLANE_ORIENTATION: str = 'Plane orientation header information could not be determined for multi-frame image.'

Message to display if plane orientation could not be read.

dicom_parser.utils.multi_frame.messages.MISSING_PLANE_POSITION: str = 'Plane position header information could not be determined for multi-frame image.'

Message to display if plane position could not be read.

dicom_parser.utils.multi_frame.messages.MISSING_SLICE_THICKNESS: str = 'Slice thickness could not be read multi-frame image pixel measures!'

Message to display if slice thickness could not be read from pixel measures.

dicom_parser.utils.multi_frame.messages.MISSING_STACK_ID: str = 'Failed to read stack IDs for a multi-frame encoded image.'

Missing stack ID in frame functional groups information.

dicom_parser.utils.multi_frame.messages.MISSING_TRANSFORMATIONS: str = 'Missing pixel value transformations sequence! Failed to parse multi-frame pixel array.'

Message to display for a missing pixel value transformations sequence.

dicom_parser.utils.multi_frame.messages.MULTIPLE_STACK_IDS: str = 'Multi-frame parsing for multipls stack IDs is not implemented.'

NotImplementedError message to display for multi stack multi-frames.

dicom_parser.utils.multi_frame.messages.SHAPE_MISMATCH: str = 'Calculated data shape does not match the number of frame!\nNumber of volumes:\t{n_volumes}\nCalculated number of frames:\t{n_calculated}\nNumber of frame according to the header: {n_frames}'

Message to display for calculated frame/shape mismatch.

dicom_parser.utils.multi_frame.multi_frame module

Definition of the MultiFrame class.

class dicom_parser.utils.multi_frame.multi_frame.MultiFrame(pixel_array: numpy.ndarray, header: dicom_parser.header.Header)

Bases: object

Handles Enhanced MR Storage SOP Class encoded data.

References

DERIVED_VOLUME_TAG: int = 1609863

Diffusion B-value tag (in integer representation), used to evaluate the inclusion of a derived volume.

PER_FRAME_GROUPS_KEY: str = 'PerFrameFunctionalGroupsSequence'

Key to use for reading the per frame functional groups sequence.

SHARED_GROUPS_KEY: str = 'SharedFunctionalGroupsSequence'

Key to use for reading the shared functional groups sequence.

STACK_ID_TAG: int = 2134102

Stack ID tag (in integer representation), used to remove any dimension indices pointing to it.

calculate_high_dim_shape(rows: int, columns: int) Tuple[int]

Calculates the image shape for high dimensionality (>3D) data.

Parameters
  • rows (int) – Number of rows in a frame

  • columns (int) – Number of columns in a frame

Returns

Image shape

Return type

Tuple[int]

Raises

DicomParsingError – Failed to parse image shape

property dimension_index_pointers: List[pydicom.tag.BaseTag]

Returns the dimensions index pointers from the header.

Returns

Dimension index pointers

Return type

List[BaseTag]

Raises

DicomParsingError – Failed to read dimension index pointers

property frame_functional_groups: int

Keeps a cached reference to per frame header information.

See also

  • get_frame_functional_groups()

Returns

Per frame header information

Return type

List[Header]

property frame_indices: numpy.ndarray

Returns an array of frame indices.

Returns

Frame indices

Return type

np.ndarray

get_data() numpy.ndarray

Returns the parsed multi-frame image pixel array.

Returns

Pixel array

Return type

np.ndarray

Raises

DicomParsingError – Failed to parse multi-frame pixel array

get_dimension_index_pointers() Tuple[pydicom.tag.BaseTag]

Returns the dimensions index pointers from the header.

Returns

Dimension index pointers

Return type

Tuple[BaseTag]

Raises

DicomParsingError – Failed to read dimension index pointers

get_frame_indices() numpy.ndarray

Returns an array of frame indices.

See also

Returns

Frame indices

Return type

np.ndarray

get_functional_groups(shared: bool = False) List[dicom_parser.header.Header]

Reads functional groups information from the header.

Parameters

shared (bool) – Whether to read the shared (rather than per frame) sequence, default is False

Returns

Frame header information

Return type

List[Header]

get_image_orientation_patient() numpy.ndarray

Returns the image position and orientation.

References

Returns

Parsed image orientation (patient) attribute information

Return type

np.array

get_image_position() numpy.ndarray

Returns the image position.

See also

Returns

Image position

Return type

np.ndarray

Raises

DicomParsingError – Image position could not be determined

get_image_shape() tuple

Returns the calculated shape of the image.

See also

Returns

Image shape

Return type

tuple

get_n_frames() int

Returns the number of frames encoded in this multi-frame data.

See also

Returns

Number of frames

Return type

int

Raises

DicomParsingError – Ambiguous number of frames

get_pixel_measures() dicom_parser.header.Header

Returns the pixel measures sequence.

Returns

Pixel measures sequence

Return type

Header

Raises

DicomParsingError – Pixel measures sequence could not be read

get_pixel_value_transformations() dicom_parser.header.Header

Returns any pixel value transformations included in the first frame’s functional groups sequence, or None.

Returns

Pixel value transformations

Return type

Header

get_scaling_parameters() numpy.ndarray

Returns the scaling parameters (slope and intercept) for the pixel array.

Returns

Scaled pixel array

Return type

np.ndarray

get_stack_ids() Tuple[str]

Returns a tuple of stack IDs by frame.

Returns

Stack IDs by frame

Return type

Tuple[str]

get_voxel_sizes() Tuple[float, float, float]

Returns the voxel sizes of the image.

See also

Returns

Voxel sizes

Return type

Tuple[float, float, float]

Raises

DicomParsingError – Voxel sizes could not be determines

property image_orientation_patient: numpy.ndarray

Returns the image position and orientation.

Returns

Parsed image orientation (patient) attribute information

Return type

np.array

property image_position: numpy.ndarray

Returns the image position.

Returns

Image position

Return type

np.ndarray

Raises

DicomParsingError – Image position could not be determined

property image_shape: tuple

Returns the calculated shape of the image.

Returns

Image shape

Return type

tuple

property n_frames: int

Returns the number of frames encoded in this multi-frame data.

See also

Returns

Number of frames

Return type

int

remove_derived_appendix(frames: List[dicom_parser.header.Header]) List[dicom_parser.header.Header]

Removes derived frames that may be appended to the data.

Parameters

frames (List[Header]) – All encoded frames

Returns

Frames without derived data

Return type

List[Header]

property shared_functional_groups: int

Keeps a cached reference to shared header information.

Returns

Shared header information

Return type

List[Header]

property stack_ids: Tuple[str]

Returns a tuple of stack IDs by frame.

See also

  • func

    get_stack_ids

Returns

Stack ID by frame

Return type

Tuple[str]

validate_high_dim_shape(shape: tuple) None

Validates the calculated image shape matches the number of frames in the dataset.

Parameters

shape (tuple) – Calculated image shape

Raises

DicomParsingError – Header/data information mismatch

validate_single_stack()

Validate single stack image.

Raises

NotImplementedError – Multi stack multi-frame images are not yet supported

property voxel_sizes: Tuple[float, float, float]

Returns the voxel sizes of the image.

Returns

Voxel sizes

Return type

Tuple[float, float, float]

Raises

DicomParsingError – Voxel sizes could not be determines