Sisyphe.core.sisypheImage

External packages/modules

class Sisyphe.core.sisypheImage.SisypheBinaryImage(image: str | Image | ndarray | vtkImageData | ANTsImage | SisypheImage | None = None, copy: bool = True, **kargs)

Description

Specialized SisypheImage class with unsigned short datatype.

Inheritance

object -> SisypheImage -> SisypheBinaryImage

Creation: 12/01/2021 Last revision: 22/06/2024

copyFromANTSImage(img: ANTsImage) None

Copy ANTs image buffer to current instance.

Parameters

imgants.core.ANTsImage

image to copy

copyFromITKImage(img: <itkTemplate itk::Image>) None

Copy ITK image buffer to current instance.

Parameters

imgitk.Image

image to copy

copyFromNumpyArray(img: ndarray, spacing: list[float] | tuple[float, float, float] = (1.0, 1.0, 1.0), origin: list[float] | tuple[float, float, float] = (0.0, 0.0, 0.0), direction: tuple | list = (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0), defaultshape: bool = True)

Copy Numpy array buffer to current instance.

Parameters

imgnumpy.ndarray

image to copy

spacingtuple[float, float, float] | list[float, float, float]

voxel sizes in mm (default 1.0, 1.0, 1.0)

origintuple[float, float, float] | list[float, float, float]

origin coordinates (default 0.0, 0.0, 0.0)

directiontuple[float, …] | list[float]

axes directions

defaultshapebool

if True, numpy shape order is reversed (i.e. z, y, x)

copyFromSITKImage(img: Image) None

Copy SimpleITK image buffer to current instance.

Parameters

imgSimpleITK.Image

image to copy

copyFromVTKImage(img: vtkImageData) None

Copy VTK image buffer to current instance.

Parameters

imgvtk.vtkImageData

image to copy

setSITKImage(img: Image) None

Shallow copy of a SimpleITK Image to the SimpleITK Image attribute of the current SisypheImage instance.

Parameters

imgSimpleITK.Image

image to copy

class Sisyphe.core.sisypheImage.SisypheImage(image: str | Image | ndarray | vtkImageData | ANTsImage | SisypheImage | None = None, **kargs)

Description

PySisyphe image class.

This class provides access to internal SimpleITK, ITK, VTK and numpy image classes, which share the same image buffer.

Overloaded operators which work with int, float, SisypheVolume, SisypheImage, SimpleITK Image, and numpy array:

  • Arithmetic +, -, /, //, *

  • Logic & (and), | (or), ^ (xor), ~ (not)

  • Relational >, >=, <, <=, ==, !=

Getter and Setter access to scalar values with slicing ability. Getter: v = instance_name[x, y, z] Setter: instance_name[x, y, z] = v x, y, z are int or slice object (syntax first:last:step)

Scope of methods:

  • copy to/from SimpleITK, ITK, VTK, ANTs, NiBabel and numpy image instances

  • various image attributes getter methods

  • descriptive statistics (minimum, maximum, median, mean, standard-deviation, percentile…)

  • IO methods for common neuroimaging file formats (BrainVoyager, Nifti, Nrrd, Minc, VTK)

Inheritance

object -> SisypheImage

Creation: 12/01/2021 Last revision: 08/04/2025

allocate(matrix: list[int] | tuple[int, int, int], datatype: str) None

Initialize image buffer.

Parameters

matrixlist[float, float, float] | tuple[float, float, float]

image size in x, y, z dimensions

datatypestr

numpy datatype

cast(datatype: str) tuple[SisypheImage, float, float]

SisypheImage copy of the current SisypheImage instance with a new datatype.

Parameters

datatypestr

numpy datatype

Returns

tuple[SisypheImage, float, float]
  • first float, slope

  • second float, intercept

  • linear transform: cast value = slope * original value + intercept, linear transform is applied if direct cast is not possible (overflow error)

copy() SisypheImage

SisypheImage copy of the current SisypheImage instance.

Returns

SisypheImage

image copy

copyComponent(c: int = 0) SisypheImage

Extract single-component SisypheImage from the current multi-component SisypheImage instance.

Parameters

cint

component index (default 0)

Returns

SisypheImage

extracted single-component image

copyFromANTSImage(img: ANTsImage) None

Copy an ANTsImage buffer to the current SisypheImage instance. Image buffer is not shared between ANTsImage image and SisypheImage instances.

Parameters

imgants.core.ANTsImage

image to copy

copyFromITKImage(img: <itkTemplate itk::Image>) None

Copy an ITKImage buffer to the current SisypheImage instance. Image buffer is not shared between ITKImage image and SisypheImage instances.

Parameters

imgitk.Image

image to copy

copyFromNibabelImage(img: Nifti1Image)

Copy a Nifti1Image to the current SisypheImage instance. Image buffer is not shared between Nifti1Image and SisypheImage instances (deep copy).

Parameters

img : nibabel.nifti1.Nifti1Image

copyFromNumpyArray(img: ndarray, spacing: list[float] | tuple[float, float, float] = (1.0, 1.0, 1.0), origin: list[float] | tuple[float, float, float] = (0.0, 0.0, 0.0), direction: tuple | list = (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0), defaultshape: bool = True) None

Copy a Numpy array buffer to the current SisypheImage instance. Image buffer is not shared between numpy array and SisypheImage instances.

Parameters

imgnumpy.ndarray

image to copy

spacinglist[float, float, float] | tuple[float, float, float],

voxel sizes in mm (default 1.0, 1.0, 1.0)

originlist[float, float, float] | tuple[float, float, float],

origin coordinates (default 0.0, 0.0, 0.0)

directionlist[float]

axes directions

defaultshapebool
  • 3D: if True, numpy array (z, y, x) shape, otherwise (x, y, z) shape

  • 4D: if True, numpy array (n, z, y, x) shape, otherwise (x, y, z, n) shape

copyFromSITKImage(img: Image) None

Copy a SimpleITK image buffer to the current SisypheImage instance. Image buffer is not shared between SimpleITK image and SisypheImage instances.

Parameters

imgSimpleITK.Image

image to copy

copyFromVTKImage(img: vtkImageData) None

Copy a VTKImageData buffer to the current SisypheImage instance. Image buffer is not shared between VTKImageData image and SisypheImage instances.

Parameters

imgvtk.vtkImageData

image to copy

copyToANTSImage(dtype: str = '', direction: bool = False) ANTsImage

ANTsImage copy of the current SisypheImage instance. Image buffer is not shared between ANTsImage and SisypheImage instances.

Parameters

dtypestr

datatype conversion (default no conversion)

directionbool

set direction to LPI+ if True (default False)

Returns

ants.core.ANTSImage

image copy

copyToITKImage() <itkTemplate itk::Image>

ITKImage copy of the current SisypheImage instance. Image buffer is not shared between ITKImage and SisypheImage instances.

Returns

itk.Image

image copy

copyToNibabelImage() Nifti1Image

Nibabel Nifti1Image copy of the current SisypheImage instance. Image buffer is not shared between Nifti1Image and SisypheImage instances (deep copy).

Returns

nibabel.nifti1.Nifti1Image

image copy

copyToNumpyArray(defaultshape: bool = True) ndarray

Numpy array copy of the current SisypheImage instance. Image buffer is not shared between numpy array and SisypheImage instances.

Parameters

defaultshapebool
  • 3D: if True returns (z, y, x) shape, otherwise returns shape (x, y, z)

  • 4D: if True returns (n, z, y, x) shape, otherwise returns shape (x, y, z, n)

Returns

numpy.ndarray

image copy

copyToSITKImage() Image

SimpleITK image copy of the current SisypheImage instance. Image buffer is not shared between SimpleITK image and SisypheImage instances.

Returns

SimpleITK.Image

image copy

copyToVTKImage() vtkImageData

VTKImageData copy of the current SisypheImage instance. Image buffer is not shared between VTKImageData and SisypheImage instances.

Returns

vtk.vtkImageData

image copy

fillWith(v: float = 0.0) None

Fill the entire image with a given value.

Parameters

vfloat

value to fill the image with (default 0.0)

flip(axis: list[bool]) None

Flip the current SisypheImage instance.

Parameters

axislist[bool]

flip axis if True, axis order x, y, z.

getArgmax(mask: str | SisypheImage | SisypheBinaryImage | None = None) tuple[int, ...] | list[tuple[int, ...]]

Get the coordinates of the highest scalar value.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

Returns

tuple[int, int, int] | list[tuple[int, int, int]]

x, y, z or list[(x, y, z)] for multicomponent image

getBackgroundThreshold(algo: str = 'mean', c: int | None = 0) float

Calc threshold to segment background.

Parameters

algostr

Automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

float

threshold to segment background

getBoundingBox(threshold: float = 0.0, margin: int = 0, blobs: bool = False) ndarray

Get the bounding box a thresholded image of the current SisypheVolume instance.

Parameters

thresholdfloat

threshold applied to scalar image (default 0.0)

marginint

isotropic margin added to the bounding box (in voxels, default 0 i.e. non margin)

blobsbool

bounding box of the whole image if False, of each image blob if True

Returns

ndarray
  • if blobs is False, 6 elements ndarray: xmin, xmax, ymin, ymax, zmin, zmax

  • if blobs is True, 6 elements ndarray for each blob of the thresholded image

getCenter() list[float] | tuple[float, float, float]

Get center of the volume as world coordinates.

Returns

tuple[float, float, float]

center of the volume

getCentroid(binary: bool = False, c: int | None = 0) tuple[float, ...]

Get centroid of the image.

Parameters

binarybool

Processing on a binary mask if True, or greyscale image (as weights) if False

cint | None
  • parameter only used for multi-component image

  • int, index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

tuple[float, …]

centroid coordinates

getComponentAllZero(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get vectors whose values are all zero in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentArgmax() SisypheImage

Get the component index of the highest scalar value of each vector in a multicomponent image.

Returns

SisypheImage

single-component image

getComponentArgmin(nonzero: bool = False) SisypheImage

Get the component index of the lowest scalar value of each vector in a multicomponent image.

Parameters

nonzerobool

exclude zero values if True

Returns

SisypheImage

single-component image

getComponentKurtosis(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get kurtosis of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentMax(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get maximum of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentMean(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get mean of each vector in a multicomponent image. Process all components or a subset selected by indices.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentMedian(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get median of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentMin(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get minimum of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentNumberOfNonZero(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get the number of non-zero values for each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentPercentile(perc: int = 25, c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get percentile of each vector in a multicomponent image.

Parameters

percint

percentile (default 25, first quartile)

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentRange(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get range (max - min) of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentSkewness(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get skewness of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getComponentStd(c: list[int] | tuple[int, ...] | slice | None = None) SisypheImage

Get standard deviation of each vector in a multicomponent image.

Parameters

cint | list[int] | tuple[int, …] | slice | None
component indices
  • list[int]: list of component indices

  • tuple[int, …]: tuple of component indices

  • slice: slice of component indices (start:end:step)

  • None: no selection, all components are processed (default)

Returns

SisypheImage

single-component image

getCrop(c: tuple | list | ndarray) SisypheImage

Get a cropped image of the current SisypheVolume instance.

Parameters

ctuple | list

xmin, xmax, ymin, ymax, zmin, zmax

Returns

SisypheImage

cropped image

getCroppedProjection(slc: int, d: str = 'left', thickness: float = 0.0, func: str = 'max', output: str = 'native', emask: SisypheImage | None = None) Image | ndarray | SisypheImage

Get a 2D projection of the current SisypheVolume instance. The projection is processed to a depth expressed in mm from the head surface (default 0.0, whole brain, no thickness). Operators applied to voxels on a projection line: maximum, mean, median, standard deviation, sum. The volume can be cut out to a specified depth (slice index) in the direction of projection.

Parameters

slcint

cutting plan (orientation is given by d parameter, see below)

dstr

direction of the projection: ‘left’, ‘right’, ‘ant’, ‘post’, ‘top’, ‘bottom’

thickness: float

projection by a given thickness in mm (default 0.0, whole brain, no thickness)

funcstr

‘max’, ‘mean’, ‘median’, ‘std’, ‘sum’

outputstr

output format: ‘numpy’ numpy.ndarray, ‘sitk’ SimpleITK.Image, ‘native’ SisypheImage

emaskSisypheImage

if mask is None (default), mask is processed from the current SisypheImage instance (automatic thresholding with Huang algorithm for grayscale images, or non-zero voxels for label images). if an explicit mask is given, array size must match the current SisypheImage instance.

Returns

SimpleITK.Image | numpy.ndarray | SisypheImage
  • SimpleITK.Image if func = ‘sitk’,

  • numpy.ndarray if func = ‘numpy’,

  • SisypheImage if func = ‘native’

getDatatype() str

Get image datatype as numpy datatype (i.e. ‘uint8’, ‘int8’, ‘uint16’, ‘int16’, ‘int32’, ‘uint32’, ‘int64’, ‘uint64’, ‘float32’, ‘float62’).

Returns

str

numpy datatype

getDatatypeAs(lib: str = 'sitk') str | int | None

Get datatype with the library format of ANTs, SimpleITK, ITK or VTK.

Parameters

libstr | int
  • library name (i.e. ‘ants’, ‘itk’, ‘sitk’, ‘vtk’)

  • library code (i.e. ants=0, itk=1, sitk=2, vtk=3)

Returns

str | int

datatype (str or int code)

getDepth() int

Get image size in z.

Returns

int

z-axis image size

getDirections() tuple[float, ...]

Get vectors of image axes in RAS+ coordinates system.

PySisyphe uses RAS+ world coordinates system convention (as MNI, Nibabel, Dipy…) with origin to corner of the voxel:

  • 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(+)

Directions is a list of 9 float, 3 vectors of 3 floats:

  • First vector, x-axis image direction, [1.0, 0.0, 0.0] (RAS+ default)

  • Second vector, y-axis image direction, [0.0, 1.0, 0.0] (RAS+ default)

  • Third vector, z-axis image direction, [0.0, 0.0, 1.0] (RAS+ default)

Returns

tuple[float, …]

vectors of image axes

getFieldOfView(decimals: int | None = None) tuple[float, float, float]

Get field of view of the volume.

Parameters

decimalsint | None

number of decimals used to round values, if None no round

Returns

tuple[float, float, float]

field of view

getFirstVectorDirection() list[float] | tuple[float, float, float]

Get first direction vector, x image axis in RAS+ coordinates system.

PySisyphe uses RAS+ world coordinates system convention (as MNI, Nibabel, Dipy…) with origin to corner of the voxel:

  • 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(+)

Directions is a list of 9 float, 3 vectors of 3 floats:

  • First vector, x-axis image direction, [1.0, 0.0, 0.0] (RAS+ default)

  • Second vector, y-axis image direction, [0.0, 1.0, 0.0] (RAS+ default)

  • Third vector, z-axis image direction, [0.0, 0.0, 1.0] (RAS+ default)

Returns

tuple[float, float, float]

vector of the x-axis image

getFlip(axis: list[bool]) SisypheImage

Get a flipped copy of the current SisypheImage instance.

Parameters

axislist[bool]

flip axis if True, axis order x, y, z.

Returns

SisypheImage

flipped image

getHeight() int

Get image size in y.

Returns

int

y-axis image size

getHistogram(mask: str | SisypheImage | SisypheBinaryImage | None = None, bins: int = 100, range: tuple[float, float] | None = None, density: bool = False, c: int = 0) ndarray

Get histogram of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

binsint

defines the number of equal-width bins in the given range.

rangetuple[float, float] | None

lower and upper range of the bins. If not provided (default None), range is simply (a.min(), a.max()), values outside the range are ignored.

densitybool

if False (default), the result will contain the number of samples in each bin. If True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1.

cint

component index

Returns

ndarray

histogram

getITKImage()

ITKImage view (pointer) of the current SisypheImage. Image buffer is shared between ITKImage and current SisypheImage instances.

Returns

itk.Image

shallow copy of image

getKurtosis(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get kurtosis of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int, index of the component to process

  • None, all components processed. In this case, the method returns a list of kurtosis values of each

component of the multi-component image

Returns

float | list[float]
  • kurtosis value for single-component image

  • kurtosis value for multi-component image, if component index c is int (default 0)

  • list of kurtosis values of each component of a multi-component image, if component index c is None

getLocalMaxima(threshold: float) ndarray

Get the local maxima of the current SisypheVolume instance.

Determine all maxima of the image with height >= threshold. The local maxima are defined as connected sets of voxels with equal scalar value strictly greater than the scalar value of all voxels in direct neighborhood of the set. A local maximum M of height threshold is a local maximum for which there is at least one path joining M with an equal or higher local maximum on which the minimal value is f(M) - h (i.e. the values along the path are not decreasing by more than h with respect to the maximum’s value) and no path to an equal or higher local maximum for which the minimal value is greater.

Parameters

thresholdfloat

local maxima threshold

Returns

ndarray

coordinates of the local maxima

getMask(algo: str = 'huang', morpho: str = '', niter: int = 1, kernel: int = 0, fill: str = '2d', c: int | None = 0) SisypheImage

Calc SisypheImage mask of the head.

Processing stages : 1. automatic thresholding of background 2. binary not of background = object 2. optional stage, iterative binary morphology 3. keep major blob 4. fill holes

Parameters

algostr

Automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

morphostr

binary morphology operator, ‘dilate’, ‘erode’, ‘open’, ‘close’ or ‘’ (default, no morphology)

niterint

number of binary morphology iterations (default 1)

kernelint

structuring element size (default 0, no morphology)

fillstr
  • ‘2d’, fill holes slice by slice

  • ‘3d’, fill holes in 3D

  • ‘’, no filling (default)

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

SisypheImage

mask

getMask2(algo: str = 'huang', morphoiter: int = 2, kernel: int = 0, c: int | None = 0) SisypheImage

Calc SisypheImage mask of the head.

Processing stages : 1. automatic thresholding of background 2. erode background 3. keep major blob (i.e.remove blobs in head/object) 4. dilate background 5. binary not of background = object 6. erode object 7. keep major blob (i.e.remove background blobs in head/object) 8. dilate object

Parameters

algostr

Automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

morphoiterint

number of binary morphology iterations (default 2)

kernelint

structuring element size, 0 automatic value (kernel=2 if spacing < 1.5 mm, kernel=1 otherwise)

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

SisypheImage

mask

getMaskROI(algo: str = 'huang', morpho: str = '', niter: int = 1, kernel: int = 0, fill: str = '2d', c: int | None = 0) SisypheROI

Calc Sisyphe.core.sisypheROI.SisypheROI mask of the head.

Parameters

algostr

Automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

morphostr

binary morphology operator, ‘dilate’, ‘erode’, ‘open’, ‘close’ or ‘’ (default, no morphology)

niterint

number of binary morphology iterations (default 1)

kernelint

structuring element size (default 0, no morphology)

fillstr
  • ‘2d’, fill holes slice by slice

  • ‘3d’, fill holes in 3D

  • ‘’, no filling

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

Sisyphe.core.sisypheROI.SisypheROI

mask

getMaskROI2(algo: str = 'huang', morphoiter: int = 2, kernel: int = 0, c: int | None = 0) SisypheROI

Calc Sisyphe.core.sisypheROI.SisypheROI mask of the head.

Parameters

algostr

Automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

morphoiterint

number of binary morphology iterations

kernelint

structuring element size, 0 automatic value (kernel=2 if spacing < 1.5 mm, kernel=1 otherwise)

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

Sisyphe.core.sisypheROI.SisypheROI

mask

getMax(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get max of image. Calculation can only be performed on non-zero values.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int, index of the component to process

  • None, all components processed. In this case, the method returns a list of max values of each component

of the multi-component image

Returns

float | list[float]
  • max value for single-component image

  • max value for multi-component image, if component index c is int (default 0)

  • list of max values of each component of a multi-component image, if component index c is None

getMean(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get mean of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int index of the component to process

  • None, all components processed. In this case, the method returns a list of mean values of each component

of the multi-component image

Returns

float | list[float]
  • mean value for single-component image

  • mean value for multi-component image, if component index c is int (default 0)

  • list of mean values of each component of a multi-component image, if component index c is None

getMedian(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get median of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int index of the component to process

  • None, all components processed. In this case, the method returns a list of median values of each component

of the multi-component image

Returns

float | list[float]
  • median value for single-component image

  • median value for multi-component image, if component index c is int (default 0)

  • list of median values of each component of a multi-component image, if component index c is None

getMemorySize(rep: str = 'B') int | float

Get the memory size of the current SisypheImage instance.

Parameters

repstr

memory unit: ‘B’ Bytes, ‘KB’ Kilobytes or ‘MB’ Megabytes

Returns

int | float,
  • int if rep == ‘B’

  • float if rep in (‘KB’, ‘MB’)

getMin(nonzero: bool = False, c: int | None = 0) float | list[float]

Get min of image. Processing can be performed on non-zero values.

Parameters

nonzerobool

exclude zero values if True

cint | None
  • parameter only used for multi-component image

  • int index of the component to process

  • None, all components processed. In this case, the method returns a list of min values of each component

of the multi-component image

Returns

float | list[float]
  • min value for single-component image

  • min value for multi-component image, if component index c is int (default 0)

  • list of min values of each component of a multi-component image, if component index c is None

getNative2DOrientation() int

Get code of the native orientation (0 3D, 1 axial, 2 coronal, 3 sagittal).

Returns

int

code of the native orientation

getNative2DOrientationAsString() tuple[str, str | None]

Get the native orientation as str.

Returns

tuple[str, str]
  • first str, mode ‘2D’ or ‘3D’

  • second str, orientation ‘Axial’, ‘Coronal’ or ‘Sagittal’

getNonZeroMask(c: int | None = 0) SisypheImage

Calc SisypheImage mask of non-zero voxels of the current SisypheImage instance.

Parameters

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

SisypheImage

mask

getNumberOfComponentsPerPixel() int

Get number of components. Array element of single component image is a scalar, array element of multi-component image is a vector. The number of components is the vector element count.

Returns

int

number of components

getNumberOfDimensions() int

Get number of dimensions.

Returns

int

number of dimensions

getNumberOfNonZero(c: int = 0) int

Get number of non-zero in image.

Parameters

cint

component index

Returns

int

number of non-zero scalar values

getNumberOfVoxels() int

Get voxel count in the array.

Returns

int

voxel count

getNumberOfVoxelsInXYPlane() int

Get voxel count in axial slice.

Returns

int

voxel count in XY plane

getNumberOfVoxelsInXZPlane() int

Get voxel count in coronal slice.

Returns

int

voxel count in XZ plane

getNumberOfVoxelsInYZPlane() int

Get voxel count in sagittal slice.

Returns

int

voxel count in YZ plane

getNumpy(defaultshape: bool = True) ndarray

Numpy array view (pointer) of the current SisypheImage instance. Image buffer is shared between numpy array and current SisypheImage instances.

Parameters

defaultshapebool
  • 3D: if True returns (z, y, x) shape, otherwise returns shape (x, y, z)

  • 4D: if True returns (n, z, y, x) shape, otherwise returns shape (x, y, z, n)

Returns

numpy.ndarray

shallow copy of image

getOrigin() list[float] | tuple[float, float, float]

Get geometrical reference origin coordinates.

Returns

tuple[float, float, float]

image origin in world coordinates

getPercentile(perc: int = 25, mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get percentile of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

percint

percentile (default 25, first quartile)

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int, index of the component to process

  • None, all components processed. In this case, the method returns a list of percentile values of each

component of the multi-component image

Returns

float | list[float]
  • percentile value for single-component image

  • percentile value for multi-component image, if component index c is int (default 0)

  • list of percentile values of each component of a multi-component image, if component index c is None

getProjection(d: str = 'left', thickness: float = 0.0, func: str = 'max', output: str = 'native', emask: SisypheImage | None = None) Image | ndarray | SisypheImage

Get a 2D projection of the current SisypheImage instance. The projection is processed to a depth expressed in mm from the head surface (default 0.0, whole brain, no thickness). Operators applied to voxels on a projection line: maximum, mean, median, standard deviation, sum.

Parameters

dstr

direction of the projection: ‘left’, ‘right’, ‘ant’, ‘post’, ‘top’, ‘bottom’

thickness: float

projection by a given thickness in mm (default 0.0, whole brain, no thickness)

funcstr

‘max’, ‘mean’, ‘median’, ‘std’, ‘sum’, ‘label’

outputstr

output format: ‘numpy’ numpy.ndarray, ‘sitk’ SimpleITK.Image, ‘native’ SisypheImage

emaskSisypheImage

if mask is None (default), mask is processed from the current SisypheImage instance (automatic thresholding with Huang algorithm for grayscale images, or non-zero voxels for label images). if an explicit mask is given, array size must match the current SisypheImage instance.

Returns

SimpleITK.Image | numpy.ndarray | SisypheImage
  • SimpleITK.Image if func = ‘sitk’,

  • numpy.ndarray if func = ‘numpy’,

  • SisypheImage if func = ‘native’

getROI(threshold: float = 0.5, op: str = '>', c: int | None = 0) SisypheROI

Converting current SisypheImage instance to Sisyphe.core.sisypheROI.SisypheROI using a threshold.

Parameters

thresholdfloat

threshold for binarization (default 0.5)

opstr

comparison operator: ‘>’ (default), ‘>=’, ‘<’, ‘<=’, ‘==’, ‘!=’, ‘0<’ (0 < x < threshold), ‘0<=’ (0 < x <= threshold)

cint | None
  • parameter only used for multi-component image

  • int index of the component to process (default 0, first component)

  • None, processing is performed on the mean image

Returns

Sisyphe.core.sisypheROI.SisypheROI

getRange(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) tuple[float, float] | list[tuple[float, float]]

Get range (min, max) of image.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int, index of the component to process

  • None, all components processed. In this case, the method returns a list of range values of each component

of the multi-component image

Returns

tuple[float, float] | list[tuple[float, float]]
  • (min, max) values for single-component image

  • (min, max) values for multi-component image, if component index c is int (default 0)

  • list of max values of each component of a multi-component image, if component index c is None

getSITKImage() Image

SimpleITK view (pointer) of the current SisypheImage instance. Image buffer is shared between SimpleITK image and current SisypheImage instances.

Returns

SimpleITK.Image

shallow copy of image

getSecondVectorDirection() list[float] | tuple[float, float, float]

Get second direction vector, y image axis in RAS+ coordinates system.

PySisyphe uses RAS+ world coordinates system convention (as MNI, Nibabel, Dipy…) with origin to corner of the voxel:

  • 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(+)

Directions is a list of 9 float, 3 vectors of 3 floats:

  • First vector, x-axis image direction, [1.0, 0.0, 0.0] (RAS+ default)

  • Second vector, y-axis image direction, [0.0, 1.0, 0.0] (RAS+ default)

  • Third vector, z-axis image direction, [0.0, 0.0, 1.0] (RAS+ default)

Returns

tuple[float, float, float]

vector of the y-axis image

getSize() list[int] | tuple[int, int, int]

Get image size, i.e. voxel count in each dimension.

Returns

tuple[int, int, int]

image size in x, y, z dimensions

getSkewness(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get skewness of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int, index of the component to process

  • None, all components processed. In this case, the method returns a list of skewness values of each

component of the multi-component image

Returns

float | list[float]
  • skewness value for single-component image

  • skewness value for multi-component image, if component index c is int (default 0)

  • list of kurtosis values of each component of a multi-component image, if component index c is None

getSpacing() list[float] | tuple[float, float, float]

Get voxel size (mm) in each dimension.

Returns

tuple[float, float, float]

voxel spacing in x, y, z

getStandardizeIntensity(method: str = 'norm') SisypheImage

Get an intensity normalized copy of the current SisypheImage instance.

Parameters

methodstr
  • ‘norm’, standardize the intensity as zscore (i.e. zero mean, [-std, +std] mapped to [-1, 1]

  • ‘rescale’, standardize the intensity values to the range [0, 1]

Returns

SisypheImage

standardized image

getStatistics(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int = 0) dict[str, float]

Get descriptive statistics of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint

component index

Returns

dict[str, float]
key/value:
  • ‘mean’: mean

  • ‘std’: standard deviation

  • ‘min’: minimum

  • ‘p25’: first quartile

  • ‘median’: median

  • ‘p75’: third quartile

  • ‘max’: maximum

  • ‘kurtosis’: kurtosis

  • ‘skewness’: skewness

getStd(mask: str | SisypheImage | SisypheBinaryImage | None = None, c: int | None = 0) float | list[float]

Get standard deviation of image. Calculation is performed on the entire image (mask parameter = None) or in a mask.

Parameters

maskstr | SisypheImage | SisypheBinaryImage | None
  • str, automatic thresholding algorithm used for background segmentation: ‘mean’, ‘otsu’, ‘huang’, ‘renyi’, ‘yen’, ‘li’, ‘shanbhag’, ‘triangle’, ‘intermodes’, ‘maximumentropy’, ‘kittler’, ‘isodata’ or ‘moments’

  • SisypheBinaryImage, binary mask image

  • None, no mask, calculation is performed on the entire image

cint | None
  • parameter only used for multi-component image

  • int index of the component to process

  • None, all components processed. In this case, the method returns a list of standard deviation values of

each component of the multi-component image

Returns

float | list[float]
  • standard deviation value for single-component image

  • standard deviation value for multi-component image, if component index c is int (default 0)

  • list of standard deviation values of each component of a multi-component image, if component index c is None

getThirdVectorDirection() list[float] | tuple[float, float, float]

Get third direction vector, z image axis in RAS+ coordinates system.

PySisyphe uses RAS+ world coordinates system convention (as MNI, Nibabel, Dipy…) with origin to corner of the voxel:

  • 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(+)

Directions is a list of 9 float, 3 vectors of 3 floats:

  • First vector, x-axis image direction, [1.0, 0.0, 0.0] (RAS+ default)

  • Second vector, y-axis image direction, [0.0, 1.0, 0.0] (RAS+ default)

  • Third vector, z-axis image direction, [0.0, 0.0, 1.0] (RAS+ default)

Returns

tuple[float, float, float]

vector of the z-axis image

getTruncateIntensity(centile: int = 1, outputrange: tuple[float, float] | None = None) SisypheImage

Get intensity truncated copy of the current SisypheImage instance. Truncate threshold is expressed in percentile (min threshold = centile, max threshold = 100 - centile). The max and min values of the output image are given in the output range parameter. If output range is None, max and min values of the output image are the max and min truncate thresholds.

Parameters

centileint

truncate threshold expressed in percentile

outputrangetuple[float, float] | None

max and min values of the output image

Returns

SisypheImage

truncated intensity image

getVTKImage() vtkImageData

VTKImageData view (pointer) of the current SisypheImage. Image buffer is shared between VTKImageData and current SisypheImage instances.

Returns

vtk.vtkImageData

shallow copy of image

getVoxelCoordinatesFromWorldCoordinates(p: list[float] | tuple[float, float, float]) list[float] | tuple[float, float, float]

Convert world coordinates to voxel grid coordinates.

Parameters

plist[float, float, float] | tuple[float, float, float]

world coordinates

Returns

tuple[float, float, float]

voxel coordinates (image reference)

getVoxelVolume() float

Get voxel volume in mm3.

Returns

float

voxel volume in mm3

getWidth() int

Get image size in x.

Returns

int

x-axis image size

getWorldCoordinatesFromVoxelCoordinates(p: list[float] | tuple[float, float, float]) list[float] | tuple[float, float, float]

Convert voxel grid coordinates to world coordinates.

Parameters

plist[float, float, float] | tuple[float, float, float]

voxel coordinates (image reference)

Returns

tuple[float, float, float]

world coordinates

hasITKImage() bool

Checks whether itk.Image attribute is available.

Returns

bool

True if itk.Image attribute is available (not None)

hasSameFieldOfView(img: SisypheImage | vtkImageData | ANTsImage | Image | list[float] | tuple[float, float, float], decimals: int = 2) bool

Compare field of view between current SisypheImage instance and other image.

Parameters

imgSisypheImage | SimpleITK.Image | itk.Image | vtk.vtkImageData | ants.core.ANTsImage | tuple[float, float, float] | list[float, float, float]

get FOV value from image attributes (SisypheImage | SimpleITK.Image | itk.Image | vtk.vtkImageData | ants.core.ANTsImage) or directly from a tuple or a list of three values

decimalsint

Number of decimal places to round to (default 2)

Returns

bool

True if same field of view

hasSameOrigin(origin: list[float] | tuple[float, float, float] | SisypheImage | vtkImageData | ANTsImage | Image | str) bool

Compare origin between the current SisypheImage instance and other image.

Parameters

originSisypheImage | SimpleITK.Image | vtk.vtkImageData | ants.core.ANTsImage | tuple[float, float, float] | list[float, float, float] | ndarray | str
  • get origin from image attribute (SisypheImage, SimpleITK.Image, itk.Image, vtk.vtkImageData, ants.core.ANTsImage),

  • or from a tuple, a list, a numpy.ndarray of three values,

  • or from template tags ‘ICBM152’, ‘ICBM452’, ‘ATROPOS’, ‘SRI24’

Returns

bool

True if same origin

hasSameSize(img: SisypheImage | vtkImageData | ANTsImage | Image | ndarray | list[int] | tuple[int, int, int])

Compare size between the current SisypheImage instance and other image.

Parameters

imgSisypheImage | SimpleITK.Image | itk.Image | vtk.vtkImageData | ants.core.ANTsImage | numpy.ndarray | tuple[int, int, int] | list[int, int, int]

image to compare

Returns

bool

True if same size

hasSameSpacing(img: SisypheImage | Image | ndarray | list[float] | tuple[float, float, float], decimals: int = 2)

Compare spacing between the current SisypheImage instance and other image.

Parameters

imgSisypheImage | SimpleITK.Image | itk.Image | vtk.vtkImageData | ants.core.ANTsImage | tuple[float, float, float] | list[float, float, float]

get spacing from image attribute (SisypheImage | SimpleITK.Image | itk.Image | vtk.vtkImageData | ants.core.ANTsImage) or directly from a tuple or a list of three values

decimalsint

Number of decimal to round to (default 2)

Returns

bool

True if same spacing

isAnisotropic(tol: float = 2.0) bool

Check whether voxel is anisotropic, i.e. not same spacing in each dimension A tolerance is applied: max(spacing) / min(spacing) > tol

Parameters

tolfloat

tolerance (default 2.0)

Returns

bool

True if max(spacing) / min(spacing) > tol

isDefaultOrigin() bool

Check whether geometrical reference origin is (0.0, 0.0, 0.0).

Returns

bool

True if world coordinates origin is (0.0, 0.0, 0.0)

isEmpty() bool

Check whether image buffer is allocated.

Returns

bool

True if image buffer is allocated

isEmptyArray() bool

Check whether image is empty i.e. all scalar values in the image array are 0.0.

Returns

bool

True if image is empty

isFloat32Datatype() bool

Check whether datatype is float32.

Returns

bool

True if float32 datatype

isFloat64Datatype() bool

Check whether datatype is float64.

Returns

bool

True if float64 datatype

isFloatDatatype() bool

Check whether datatype is float (‘float32’ or ‘float64’).

Returns

bool

True if float datatype

isInt16Datatype() bool

Check whether datatype is int16.

Returns

bool

True if int16 datatype

isInt32Datatype() bool

Check whether datatype is int32.

Returns

bool

True if int32 datatype

isInt64Datatype() bool

Check whether datatype is int64.

Returns

bool

True if int64 datatype

isInt8Datatype() bool

Check whether datatype is int8.

Returns

bool

True if int8 datatype

isIntegerDatatype() bool

Check whether datatype is integer (‘uint8’, ‘int8’, ‘uint16’, ‘int16’, ‘uint32’, ‘int32’, ‘uint64’ or ‘int64’).

Returns

bool

True if integer datatype

isIsotropic(tol: float = 2.0) bool

Check whether voxel is isotropic, i.e. same spacing in each dimension. A tolerance is applied: max(spacing) / min(spacing) <= tol

Parameters

tolfloat

tolerance (default 2.0)

Returns

bool

True if max(spacing) / min(spacing) < tol

isMulticomponent() bool

Check whether image is multicomponent (array element is a vector and not a scalar value).

Returns

bool

True if multicomponent image

isThickAnisotropic(tol: float = 2.0, thickness: float = 3.0) bool

Check if the voxel is anisotropic and thicker than a given slice thickness in mm. A tolerance is applied for anisotropy: max(spacing) / min(spacing) > tol.

Parameters

tolfloat

tolerance (default 2.0)

thicknessfloat

slice thickness threshold (default 3.0 mm)

Returns

bool

True if max(spacing) / min(spacing) > tol and max(spacing) >= thickness

isUInt16Datatype() bool

Check whether datatype is uint16.

Returns

bool

True if uint16 datatype

isUInt32Datatype() bool

Check whether datatype is uint32.

Returns

bool

True if uint32 datatype

isUInt64Datatype() bool

Check whether datatype is uint64.

Returns

bool

True if uint64 datatype

isUInt8Datatype() bool

Check whether datatype is uint8.

Returns

bool

True if uint8 datatype

loadFromBrainVoyagerVMR(filename: str) dict

Load the current SisypheImage instance from a BrainVoyager (.vmr) file.

Parameters

filenamestr

BrainVoyager file name

loadFromFreeSurferMGH(filename: str) None

Load the current SisypheImage instance from a FreeSurfer MGH (.mgh, .mgz) file.

Parameters

filenamestr

FreeSurfer file name

loadFromMINC(filename: str) None

Load the current SisypheImage instance from a Minc (.minc) file.

Parameters

filenamestr

Minc file name

loadFromNIFTI(filename: str, reorient: bool = True) None

Load the current SisypheImage instance from a Nifti (.nii) file.

Parameters

filenamestr

Nifti file name

reorientbool

conversion to RAS+ world coordinates convention if True (default True)

loadFromNRRD(filename: str) None

Load the current SisypheImage instance from a Nrrd (.nrrd) file.

Parameters

filenamestr

Nrrd file name

loadFromNumpy(filename: str) None

Load the current SisypheImage instance from a numpy (.npy) file.

Parameters

filenamestr

numpy file name

loadFromSisyphe(filename: str) dict

Load the current SisypheImage instance from an old Sisyphe (.vol) file.

Parameters

filenamestr

old Sisyphe binary file name

Returns

dict

Old Sisyphe header (see Sisyphe.sisypheImageIO.loadFromSisyphe docstring for keys and values documentation)

loadFromVTK(filename: str) None

Load the current SisypheImage instance from a VTK (.vtk) file.

Parameters

filenamestr

VTK file name

noiseEstimate() float

Estimator of the (Gaussian) noise standard deviation.

Returns

float

noise standard deviation

removeNeckSlices(f: float = 1.8) SisypheImage

Get a new SisypheImage instance, cropped in z. Most sagittal MRI scans have extensive and useless inferior coverage. This function crop MR volume in z direction, removing empty slices and lower slices of neck below foramen magnum.

Parameters

ffloat

multiplicative factor to adjust the neck slice. Lower values remove more slices, higher values keep more slices (between 1.5 and 2.0, default 1.8 close to the foramen magnum for most MR images)

Returns

SisypheImage

replaceNanInfValues(nan: float = 0.0, posinf: float = 0.0, neginf: float = 0.0) None

Replace NaN and Inf values with a given values.

Parameters

nanfloat, optional

value to replace NaN (default 0.0)

posinffloat, optional

value to replace positive infinity (default 0.0)

neginffloat, optional

value to replace negative infinity (default 0.0)

saveToJSON(filename: str) None

Save the current SisypheImage instance to a Json (.json) file.

Parameters

filenamestr

Json file name

saveToMINC(filename: str) None

Save the current SisypheImage instance to a Minc (.minc) file.

Parameters

filenamestr

Minc file name

saveToNIFTI(filename: str, compress: bool = False) None

Save the current SisypheImage instance to a Nifti (.nii) file.

Parameters

filenamestr

Nifti file name

compressbool

gzip compression if True (default False)

saveToNRRD(filename: str) None

Save the current SisypheImage instance to a Nrrd (.nrrd) file.

Parameters

filenamestr

Nrrd file name

saveToNumpy(filename: str) None

Save the current SisypheImage instance to a numpy (.npy) file.

Parameters

filenamestr

numpy file name

saveToVTK(filename: str) None

Save the current SisypheImage instance to a vtk (.vtk) file.

Parameters

filenamestr

VTK file name

setDefaultOrigin() None

Set geometrical reference origin coordinates to (0.0, 0.0, 0.0).

setDirections(direction: list | tuple = (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)) None

Set vectors of image axes in RAS+ coordinates system. PySisyphe uses RAS+ world coordinates system convention (as MNI, Nibabel, Dipy…) with origin to corner of the voxel.

  • 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(+)

Directions is a list of 9 float, 3 vectors of 3 floats

  • First vector, x image axis direction, [1.0, 0.0, 0.0] (RAS+ default)

  • Second vector, y image axis direction, [0.0, 1.0, 0.0] (RAS+ default)

  • Third vector, y image axis direction, [0.0, 0.0, 1.0] (RAS+ default)

Parameters

direction tuple[float, …]

9 elements, vectors of image axes

setOrigin(origin: list[float] | tuple[float, float, float] = (0.0, 0.0, 0.0)) None

Set geometrical reference origin coordinates.

Parameters

originlist[float, float, float] | tuple[float, float, float]

image origin in world coordinates

setOriginToCenter() None

Set geometrical reference origin coordinates to image center.

setSITKImage(img: Image) None

Shallow copy of a SimpleITK Image to the current SisypheImage instance. Image buffer is shared between SimpleITK image and current SisypheImage instances.

Parameters

imgSimpleITK.Image

image to copy

setSpacing(sx: float, sy: float, sz: float) None

Set voxel size (mm) in each dimension.

Parameters

sxfloat

voxel spacing in x

syfloat

voxel spacing in y

szfloat

voxel spacing in x

sliceHeadSurface(orient: str = 'e') dict[str, list]

Get head surface (number of pixels) in each slice of the current SisypheImage instance.

Parameters

orientstr

slice orientation (‘a’ axial, ‘c’ coronal, ‘s’ sagittal, ‘e’ every orientation default)

Returns

dict[str, list]
  • keys: ‘a’ axial results, ‘c’ coronal results, ‘s’ sagittal results

  • dict value is list with four elements

  • first element = int, index of the slice with the maximum head surface

  • second element = int, index of the first slice with non-zero head surface

  • third element = int, index of the last slice with non-zero head surface

  • fourth element = numpy.ndarray, head surface (number of pixels) of each slice

sliceIsEmpty(index: int | list[int] | tuple[int, ...], orient: int) bool

Check whether slices are empty i.e. all scalar values in slices are 0.0.

Parameters

indexint | list[int] | tuple[int, …]

slice indices

orientint

slice orientation code (0 axial, 1 coronal, 2 sagittal)

Returns

bool

True if slices are empty

standardizeIntensity(method: str = 'norm') None

Intensity normalization of the current SisypheImage instance.

Parameters

methodstr
  • ‘norm’, standardize the intensity as zscore (i.e. zero mean, [-std, +std] mapped to [0, 1]

  • ‘rescale’, standardize the intensity values to the range [0, 1]

truncateIntensity(centile: int = 1, outputrange: tuple[float, float] | None = None)

Truncate intensity of the current SisypheImage instance. Truncate threshold is expressed in percentile (min threshold = centile, max threshold = 100 - centile). The max and min values of the output image are given in the output range parameter. If output range is None, max and min values of the output image are the max and min truncate thresholds.

Parameters

centileint

truncate threshold expressed in percentile

outputrangetuple[float, float] | None

max and min values of the output image

Sisyphe.core.sisypheImage.numpyToVtkImageData(np: ndarray) vtkImageData

numpy ndarray to vtk.vtkImageData conversion.

Parameters

npnumpy.ndarray

numpy array to convert

Returns

vtk.vtkImageData

converted vtkImageData

Sisyphe.core.sisypheImage.simpleITKToVTK(img: Image) vtkImageData

SimpleITK.Image to vtk.vtkImageData conversion.

Parameters

imgSimpleITK.Image

SimpleITK.Image to convert

Returns

vtk.vtkImageData

converted vtkImageData