Image#

class zrad.image.Image(array=None, origin=None, spacing=None, direction=None, shape=None)[source]#

Image volume with voxel data and physical geometry metadata.

Image stores arrays in NumPy order while preserving the origin, spacing, direction, and size used by SimpleITK. The class is used throughout preprocessing, filtering, and radiomics to keep image data aligned with ROI masks.

Parameters:
  • array (numpy.ndarray or None, optional) – Voxel array. Image data are typically stored in (z, y, x) order.

  • origin (sequence of float or None, optional) – Physical origin of the image in SimpleITK (x, y, z) order.

  • spacing (sequence of float or None, optional) – Physical voxel spacing in SimpleITK (x, y, z) order.

  • direction (sequence of float or None, optional) – Flattened 3D direction cosine matrix.

  • shape (sequence of int or None, optional) – Image size in SimpleITK (x, y, z) order.

Methods

copy()

Return a deep copy of the image data and geometry.

from_dicom(dicom_dir, modality)

Create an image from a DICOM series.

from_dicom_mask(rtstruct_path, ...[, dicom_dir])

Create a DICOM RTSTRUCT or SEG mask aligned to a reference image.

from_nifti(image_path)

Create an image from a NIfTI file.

from_nifti_mask(mask_path, reference)

Create a NIfTI mask aligned to a reference image.

resample_to_target(target[, interpolator])

Resample this image onto the physical grid of another image.

save_as_nifti(output_path)

Write the image to a NIfTI file.

Image.copy()[source]#

Return a deep copy of the image data and geometry.

Returns:

image – New image with copied array, origin, spacing, direction, and shape.

Return type:

Image

classmethod Image.from_dicom(dicom_dir, modality)[source]#

Create an image from a DICOM series.

Parameters:
  • dicom_dir (str or path-like) – Directory containing the DICOM series.

  • modality (str) – Imaging modality used by the DICOM reader.

Returns:

image – Image populated with voxel data and geometry read from the series.

Return type:

Image

classmethod Image.from_dicom_mask(rtstruct_path, structure_name, reference, dicom_dir=None)[source]#

Create a DICOM RTSTRUCT or SEG mask aligned to a reference image.

Parameters:
  • rtstruct_path (str or path-like) – Path to an RTSTRUCT or BINARY DICOM SEG file.

  • structure_name (str) – RTSTRUCT ROI name or DICOM SEG SegmentLabel to extract.

  • reference (Image) – Reference image that defines the target grid and geometry.

  • dicom_dir (str or path-like, optional) – Directory containing the referenced source DICOM image series. Supply it for SEG input so source-frame references can be resolved and checked, including frames without independent spatial geometry. RTSTRUCT loading does not use this argument.

Returns:

mask – Binary mask image aligned to the reference geometry.

Return type:

Image

classmethod Image.from_nifti(image_path)[source]#

Create an image from a NIfTI file.

Parameters:

image_path (str or path-like) – Path to the NIfTI image file.

Returns:

image – Image populated with voxel data and geometry read from the file.

Return type:

Image

classmethod Image.from_nifti_mask(mask_path, reference)[source]#

Create a NIfTI mask aligned to a reference image.

Parameters:
  • mask_path (str or path-like) – Path to the NIfTI mask file.

  • reference (Image) – Reference image that defines the target grid and geometry.

Returns:

mask – Binary mask image resampled onto the reference geometry.

Return type:

Image

Image.resample_to_target(target, interpolator=2)[source]#

Resample this image onto the physical grid of another image.

Values outside this image’s physical extent are filled with its minimum intensity. The returned image has the target’s origin, spacing, direction, and shape; neither input image is modified.

Parameters:
  • target (Image) – Image whose physical grid defines the resampling output.

  • interpolator (int, optional) – SimpleITK interpolator enum, such as sitk.sitkLinear or sitk.sitkNearestNeighbor. The default is linear interpolation.

Returns:

image – A new image containing this image resampled onto target.

Return type:

Image

Image.save_as_nifti(output_path)[source]#

Write the image to a NIfTI file.

Parameters:

output_path (str or path-like) – Destination file path for the written NIfTI image.