4D Image Conversion

Utilities for converting 4D medical images into a 3D time-series sequence. .nrrd inputs (including Slicer .seq.nrrd heart sequences, whose per-voxel vector dimension exceeds ITK Python’s wrapped Vector sizes) are read with pynrrd; all other formats (NIfTI .nii.gz, MHA, …) are read with itk.imread and must be true 4-dimensional images.

Module Reference

Convert a 3D or 4D image into a sequence of 3D images.

Reads a 3D or 4D medical image and, for the 4D case, splits it along the temporal axis into individual 3D ITK volumes. Origin, spacing, and direction are preserved in each per-frame volume. A pure 3D input becomes a one-element time series.

Three reader paths are used:

  • A directory path is treated as a DICOM series and read with pydicom. The slices are grouped by temporal position (TemporalPositionIdentifier or TriggerTime); each group yields one 3D ITK image. Directories that contain a single phase produce a single 3D image.

  • .nrrd files: 4D Slicer .seq.nrrd heart sequences (whose per-voxel vector dimension exceeds ITK Python’s wrapped Vector sizes) go through pynrrd. Plain 3D NRRDs fall back to itk.imread.

  • Every other format goes through itk.imread and may be either 3D or 4D (e.g. NIfTI .nii.gz with dim[0] == 3 or 4).

class physiomotion4d.convert_image_4d_to_3d.ConvertImage4DTo3D(log_level=20)[source]

Split a 3D/4D ITK image into a list of 3D ITK images.

__init__(log_level=20)[source]

Initialize the 4D-to-3D image converter.

Parameters:

log_level (int | str) – Logging level (default: logging.INFO)

load_image_4d(filename)[source]

Load a 3D or 4D image and populate self.img_3d with 3D frames.

Dispatch rules:

  • A directory path is read as a DICOM series via pydicom. Slices are grouped by temporal phase; each group becomes one 3D ITK image. A 3D-only directory produces a single 3D image.

  • .nrrd files use pynrrd for true 4D Slicer .seq.nrrd inputs and fall back to itk.imread for plain 3D NRRDs.

  • All other formats go through itk.imread; the array may be 3D or 4D and is treated uniformly as a (1 or T)-frame sequence.

Parameters:

filename (Union[str, Path]) – Path to a 3D/4D image file, or a DICOM series directory.

Return type:

None

get_3d_image(index)[source]

Return the 3D ITK image at the given time index.

Return type:

Image

get_number_of_3d_images()[source]

Return the number of 3D images currently held.

Return type:

int

save_3d_images(directory, basename, suffix='mha')[source]

Write each held 3D image to {directory}/{basename}_{i:03d}.{suffix}.

Parameters:
  • directory (Union[str, Path]) – Output directory; created if it does not exist.

  • basename (str) – Filename stem used for every saved volume.

  • suffix (str) – File extension (default: mha).

Return type:

None

Navigation

Contour Tools | Utility Modules | API Reference