Sisyphe.core.sisypheImageIO

External packages/modules

Sisyphe.core.sisypheImageIO.compareDataElementsBetweenDatasets(ds1: Dataset, ds2: Dataset, equality: bool = False) Dataset

Create a dataset with DICOM fields that have the same values as the two tested datasets (ds1, ds2 parameters).

Parameters

ds1pydicom.Dataset

first dataset to compare

ds2pydicom.Dataset

second dataset to compare

equalitybool

test equality if True, difference otherwise

Returns

pydicom.Dataset

dataset

Sisyphe.core.sisypheImageIO.convertImageToAxialOrientation(img: Image) tuple[Image, list[int]]

SimpleITK image reorientation to axial. ex. coronal to axial -> order = 0, 2, 1 (x, z, y) ex. sagittal to axial -> order = 1, 2, 0 (y, z, x)

Parameters

imgSimpleITK.Image

image to reorient

Returns

tuple[SimpleITK.Image, list[int]]
  • SimpleITK.Image, reoriented image

  • list[int] order of dimensions

Sisyphe.core.sisypheImageIO.convertSITKtoVTK(img: Image) vtkImageData

SimpleITK image to VTK image conversion.

Parameters

imgSimpleITK.Image

image to copy

Returns

vtk.vtkImageData

image copy

Sisyphe.core.sisypheImageIO.convertVTKtoSITK(img: vtkImageData) Image

VTK image to SimpleITK image conversion.

Parameters

imgvtk.vtkImageData

image to copy

Returns

SimpleITK.Image

image copy

Sisyphe.core.sisypheImageIO.extractDataElementValuesFromDatasets(dslist: list[FileDataset | Dataset | str], taglist: list[BaseTag]) dict

Extract all the values of multiple dicom Tag (taglist parameter) in multiple datasets (dslist parameter).

Parameters

dslistlist[pydicom.Dataset]

list of datasets

taglistlist[pydicom.BaseTag]

list of tags

Returns

dict
  • key, pydicom.BaseTag

  • value, list of values of each pydicom.Dataset in dslist

Sisyphe.core.sisypheImageIO.flipImageToVTKDirectionConvention(img: Image) Image

Flip sitkImage to VTK/SisypheVolume RAS+ orientation convention.

SisypheVolume is in RAS+ world coordinates convention (as MNI, Nibabel, Dipy…)

  • x, direction[1.0, 0.0, 0.0]: left(-) to right(+)

  • y, direction[0.0, 1.0, 0.0]: posterior(-) to anterior(+)

  • z: direction[0.0, 0.0, 1.0]: inferior(-) to superior(+)

SimpleITK/ITK is in LPS+ world coordinates convention

  • x right(-) to left(+), if sitkImage direction is [1.0, 0.0, 0.0] -> Flip X

  • y anterior (-) to posterior (+), if sitkImage direction is [0.0, 1.0, 0.0] -> Flip Y

  • z inferior (-) to superior (+), if sitkImage direction is [0.0, 0.0,-1.0] -> Flip Z

Parameters

imgSimpleITK.Image

image to flip

Returns

SimpleITK.Image

flipped image

Sisyphe.core.sisypheImageIO.isDicom(f: str) bool

Test if a file is in Dicom format

Parameters

fstr

filename

Returns

bool

True if DICOM file

Sisyphe.core.sisypheImageIO.readFromBitmap(filename: str, lib: str = 'sitk') Image

Read Bitmap file (.bmp, .jpg, .jpeg, .png, .tiff).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readFromBrainVoyagerVMR(filename: str, lib: str = 'sitk') tuple[Image, dict]

Read BrainVoyager VMR file (.vmr).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

tuple[SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage, dict]
  • image instance

  • dict, header of BrainVoyager VMR image format

Sisyphe.core.sisypheImageIO.readFromDicomDirectory(directory: str) Image

Read DICOM files in a directory.

Parameters

directorystr

directory of the dicom files to convert

Returns

SimpleITK.Image

image instance

Sisyphe.core.sisypheImageIO.readFromDicomFilenames(filenames: list[str]) Image

Read a list of DICOM files.

Parameters

filenameslist[str]

dicom filenames to convert

Returns

SimpleITK.Image

image instance

Sisyphe.core.sisypheImageIO.readFromDicomSeries(filename: list[str]) Image

Read a list of DICOM files.

Parameters

filenamestr

one dicom filename of the series to convert

Returns

SimpleITK.Image

image instance

Sisyphe.core.sisypheImageIO.readFromFreeSurferMGH(filename: str, lib: str = 'sitk') Image

Read FreeSurfer MGH file (.mgh, .mgz).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readFromMINC(filename: str, lib: str = 'sitk') Image

Read MINC file (.mnc).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readFromNIFTI(filename: str, lib: str = 'sitk') Image

Read Nifti file (.nii, .hdr, .img, .nia, .nii.gz, .img.gz).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readFromNRRD(filename: str, lib: str = 'sitk') Image

Read NRRD file (.nrrd, .nhdr).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readFromNumpy(filename: str, defaultshape: bool = True, lib: str = 'sitk') Image

Read Numpy file (.npy).

Parameters

filenamestr

image file name

defaultshapebool

shape (z, y, x) if True, (x, y, z) if False

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readFromSisyphe(filename: str, lib: str = 'sitk') tuple[Image, dict]

Read Sisyphe file (.vol).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

tuple[SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage, dict]
  • image instance

  • dict, header of Sisyphe image format

Sisyphe.core.sisypheImageIO.readFromSisypheROI(filename: str, lib: str = 'sitk') tuple[list[Image], dict]

Read sitkImage.

Parameters

filenamestr

ROI file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

tuple[SimpleITK.Image, dict]
  • image instance

  • dict, header of Sisyphe ROI image format, key = string of field, value of field

Sisyphe.core.sisypheImageIO.readFromVTK(filename: str, lib: str = 'sitk') Image

Read VTK file (.vtk, .vti).

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.readImage(filename: str, lib: str = 'sitk') Image | tuple[Image, dict]

Read image from Nifti, Nrrd, Minc, VTK, Numpy, old Sisyphe, or Bitmap format. Format is detectied from filename extension. Instance returned can be SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage.

Parameters

filenamestr

image file name

libstr

format of returned image ‘itk’, ‘vtk’, ‘ants’ or by default ‘sitk’

Returns

SimpleITK.Image | itk.Image | vtk.ImageData | ants.core.ANTsImage

image instance

Sisyphe.core.sisypheImageIO.writeToJSON(img: Image, filename: str) None

Write SimpleITK image to disk with JSON format (.json)

Parameters

imgSimpleITK.Image

image to save

filenamestr

file save name

Sisyphe.core.sisypheImageIO.writeToMINC(img: Image, filename: str) None

Write SimpleITK image to disk with MINC format (.mnc).

Parameters

imgSimpleITK.Image

image to save

filenamestr

file save name

Sisyphe.core.sisypheImageIO.writeToNIFTI(img: Image, filename: str, compression: bool = False) None

Write SimpleITK image to disk with NIFTI format (.nii, .hdr, .img, .nia, .nii.gz, .img.gz).

Parameters

imgSimpleITK.Image

image to save

filenamestr

file save name

compressionbool

write compressed format nii.gz if True, default is False

Sisyphe.core.sisypheImageIO.writeToNRRD(img: Image, filename: str) None

Write SimpleITK image to disk with NRRD format (.nrrd, .nhdr).

Parameters

imgSimpleITK.Image

image to save

filenamestr

file save name

Sisyphe.core.sisypheImageIO.writeToNumpy(img: Image, filename: str) None

Write SimpleITK image to disk with Numpy format (.npy)

Parameters

imgSimpleITK.Image

image to save

filenamestr

file save name

Sisyphe.core.sisypheImageIO.writeToVTK(img: Image, filename: str) None

Write SimpleITK image to disk with VTK format (.vtk)

Parameters

imgSimpleITK.Image

image to save

filenamestr

file save name