CreateImageFromMask#
- class medicalimageanalysis.utils.creation.CreateImageFromMask(array, origin, spacing, image_name, dimensions=None, orientation=None, plane='Axial', description='Mask to Image', modality='CT')[source]
Bases:
objectBuilds DICOM headers for an array and registers it in
Data.imageas anImage.The instance exposes the same attributes a DICOM reader does (
image_set,array,image_matrix, …), soImagecan be constructed from it directly. Nothing is written to disk.- Parameters:
array ((Z, Y, X) ndarray) – Image or mask array.
origin ((3,) array_like) – Patient position (mm) of the first voxel.
spacing ((3,) array_like) – Voxel spacing (x, y, z) in mm.
image_name (str) – Key used in
Data.image.dimensions (tuple of int, optional) – Array dimensions (z, y, x). Defaults to
array.shape.orientation ((6,) array_like, optional) – ImageOrientationPatient (row direction, column direction). Defaults to [1, 0, 0, 0, 1, 0].
plane (str) – Acquisition plane.
description (str) – Series Description.
modality ({'CT', 'MR', 'PT'}) – Modality, which also sets the SOP Class UID.
Examples
>>> import numpy as np >>> creator = CreateImageFromMask(np.zeros((8, 32, 16), dtype=np.uint8), [0, 0, 0], [1, 1, 2], 'Mask') >>> len(creator.image_set), creator.image_set[0].Rows, creator.image_set[0].Columns (8, 32, 16)
- add_image()[source]
Creates an
Imagefrom this instance and stores it asData.image[image_name].- Return type:
None
Examples
>>> import numpy as np >>> import medicalimageanalysis as mia >>> creator = CreateImageFromMask(np.zeros((8, 32, 32), dtype=np.uint8), [0, 0, 0], [1, 1, 2], 'Mask') >>> creator.add_image() >>> 'Mask' in mia.Data.image True
- add_mesh_roi(mesh, roi_name, color=None, visible=False)[source]
Adds a mesh as an ROI of the registered image, calling
add_image()first if needed.- Parameters:
- Returns:
Sets the ROI’s mesh, volume, com and bounds.
- Return type:
None
Examples
>>> import numpy as np >>> import pyvista as pv >>> import medicalimageanalysis as mia >>> creator = CreateImageFromMask(np.zeros((8, 32, 32), dtype=np.uint8), [0, 0, 0], [1, 1, 2], 'Mask') >>> creator.add_mesh_roi(pv.Sphere(radius=5, center=(16, 16, 8)), 'Sphere') >>> 'Sphere' in mia.Data.image['Mask'].roi True
- compute_position(z)[source]
Returns the patient position (mm) of the first voxel of a slice.
Examples
>>> import numpy as np >>> creator = CreateImageFromMask(np.zeros((8, 32, 32), dtype=np.uint8), [0, 0, 0], [1, 1, 2], 'Mask') >>> creator.compute_position(3).tolist() [0.0, 0.0, 6.0]