image_io module¶
Wrappers for saving and loading DWIs of 3D printed phantoms.
In this module, images are classified as DWIs or derived images. A DWI should be the raw 4D data from a diffusion MRI scan, and have associated information about the diffusion gradients. A derived image should be (usually) 3D data from analysis of a DWI.
Either of the two may have a mask associated with them.
-
class
image_io.
DerivedImage
(img)¶ Bases:
object
Wrapper class including an image of data derived from a DWI.
Parameters: img (SpatialImage) – The NiBabel image of the derived data. -
get_flat_data
()¶ A 1D numpy array with the image data.
-
get_image
()¶ A 3D numpy array with the image data.
-
-
class
image_io.
DiffusionWeightedImage
(img, gtab)¶ Bases:
object
Wrapper class including image and gradient data.
Parameters: - img (SpatialImage) – The NiBabel image of the DWI
- gtab (GradientTable) – The DIPY gradient table associated with the scan
-
get_flat_data
()¶ A 1D numpy array with the image data.
-
get_image
()¶ A 3D numpy array with the image data.
-
class
image_io.
MaskedDerivedImage
(img, mask)¶ Bases:
image_io.DerivedImage
Wraps an image of data derived from a DWI with a mask.
Parameters: - img (SpatialImage) – The NiBabel image of the derived data.
- mask (array_like) – A 3D binary numpy array, where 1s indicate voxels to be included.
-
get_flat_data
()¶ A 1D numpy array with the masked derived data.
-
get_image
()¶ A 3D numpy array with the derived data, ignoring the mask.
-
class
image_io.
MaskedDiffusionWeightedImage
(img, gtab, mask)¶ Bases:
image_io.DiffusionWeightedImage
Wrapper class including an image, mask, and gradient data.
Parameters: - img (SpatialImage) – The NiBabel image of the DWI
- gtab (GradientTable) – The DIPY gradient table associated with the scan
- mask (array_like) – A binary numpy array, where 1s indicate voxels to be included.
-
get_flat_data
()¶ A 1D numpy array with only the masked data.
-
get_image
()¶ A 3D numpy array with the image data, ignoring the mask.
-
image_io.
gen_table
(derived_images)¶ Organize the model outputs for a phantom in a table.
Parameters: derived_images (collection of MaskedDerivedImages) – A collection of derived images, each corresponding to a single model output from the same phantom. Each of these images must have the same mask associated with them. Returns: A table where each row corresponds to one voxel, and each column corresponds to one derived image. Return type: array_like
-
image_io.
load_derived_image
(image_path, mask_path=None)¶ Load the data from a derived image.
Parameters: - image_path (string) – Path to the nifti derived data volume.
- mask_path (string, optional) – Path to the nifti mask, if one exists
Returns: img – The derived data with a mask, if applicable.
Return type:
-
image_io.
load_dwi
(nifti_path, bval_path, bvec_path, mask_path=None, b0_threshold=250)¶ Load the data needed to process a diffusion-weighted image.
Parameters: - nifti_path (string) – Path to the nifti DWI
- bval_path (string) – Path to the .bval file
- bvec_path (string) – Path to the .bvec file
- mask_path (string, optional) – Path to the nifti mask, if one exists
- b0_threshold – Threshold below which a b-value is considered zero
Returns: img – The DWI data with a mask, if applicable.
Return type:
-
image_io.
save_image
(data, affine, output_path)¶ Save some data to a nifti file.
Parameters: - data (array_like) – The image data to be saved
- affine – The affine transform to be used
- output_path (string) – Path to the file to be saved