opentps.core.processing.imageProcessing package

Submodules

opentps.core.processing.imageProcessing.crop2D module

crop2DDataAroundBox(data: Image2D, box, marginInMM=[0, 0, 0])

Crop the data around the box with a margin in mm

Parameters:
  • data (Image2D) – data to be cropped.

  • box (Sequence[Sequence[float]]) – [[Xmin,xMax], [Ymin,Ymax]] :coordinates of the box to be cropped around.

  • marginInMM (Sequence[float]) – margin in mm to be added to the box.

getBoxAroundROI(ROI: Image2D) Sequence[Sequence[float]]
Get the box universal coordinates around the ROI ([[Xmin,xMax],

[Ymin,Ymax]])

Parameters:

ROI (Image2D) – ROI to be cropped.

Returns:

[[Xmin,xMax], [Ymin,Ymax]] :coordinates of the box.

Return type:

Sequence[Sequence[float]]

opentps.core.processing.imageProcessing.cupyImageProcessing module

applyTransform3D(data, tformMatrix: ndarray, fillValue: float = 0.0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0], interpOrder=1, mode='constant')

Apply a 3D transformation to an image or a vector field

Parameters:
  • data (Image3D or VectorField3D) – the data to be transformed

  • tformMatrix (np.ndarray) – the transformation matrix

  • fillValue (float) – the value to fill the data for points coming, after rotation, from outside the image. Default is 0

  • outputBox (str) – the cube in space represented by the result after rotation (‘same’, ‘keepAll’). Default is ‘keepAll’

  • rotCenter (str or sequence[float]) – the center of rotation. Default is dicomOrigin

  • translation (sequence[float]) – the translation to apply to the data after rotation. Default is [0, 0, 0]

  • interpOrder (int) – the order of the interpolation (0, 1, 2, 3, 4) default is 1

  • mode (str) – the mode of the interpolation (‘constant’, ‘nearest’, ‘reflect’, ‘wrap’). Default is ‘constant’

applyTransform3DToImage3D(image: Image3D, tformMatrix: ndarray, fillValue: float = 0.0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0], interpOrder=1, mode='constant')

Apply a 3D transformation to an image

Parameters:
  • image (Image3D) – the image to be transformed

  • tformMatrix (np.ndarray) – the transformation matrix

  • fillValue (float) – the value to fill the data for points coming, after rotation, from outside the image. Default is 0

  • outputBox (str) – the cube in space represented by the result after rotation (‘same’, ‘keepAll’). Default is ‘keepAll’

  • rotCenter (str or sequence[float]) – the center of rotation. Default is ‘dicomOrigin’

  • translation (sequence[float]) – the translation to apply to the data after rotation. Default is [0, 0, 0]

  • interpOrder (int) – the order of the interpolation (0, 1, 2, 3, 4) default is 1

  • mode (str) – the mode of the interpolation (‘constant’, ‘nearest’, ‘reflect’, ‘wrap’). Default is ‘constant’

applyTransform3DToVectorField3D(vectField: VectorField3D, tformMatrix: ndarray, fillValue: float = 0.0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0], interpOrder=1, mode='constant')

Apply a 3D transformation to a vector field

Parameters:
  • vectField (VectorField3D) – the vector field to be transformed

  • tformMatrix (np.ndarray) – the transformation matrix

  • fillValue (float) – the value to fill the data for points coming, after rotation, from outside the image. Default is 0

  • outputBox (str) – the cube in space represented by the result after rotation (‘same’, ‘keepAll’). Default is ‘keepAll’

  • rotCenter (str or sequence[float]) – the center of rotation. Default is ‘dicomOrigin’

  • translation (sequence[float]) – the translation to apply to the data after rotation. Default is [0, 0, 0]

  • interpOrder (int) – the order of the interpolation (0, 1, 2, 3, 4) default is 1

  • mode (str) – the mode of the interpolation (‘constant’, ‘nearest’, ‘reflect’, ‘wrap’). Default is ‘constant’

closeMask(mask, radius=1.0, struct=None, inPlace=True)

close a mask by a given radius

Parameters:
  • mask (Image3D) – the mask to close

  • radius (float) – the radius of the closing in mm. Default is 1.0

  • struct (ndarray) – the structuring element to use for the closing. Default is None

  • inPlace (bool) – if True, the mask is closed in place, if False, a copy of the mask is returned. Default is True

Returns:

the closed mask if inPlace is False, None otherwise

Return type:

Image3D

dilateMask(mask, radius=1.0, struct=None, inPlace=True)

dilate a mask by a given radius

Parameters:
  • mask (Image3D) – the mask to dilate

  • radius (float) – the radius of the dilation in mm. Default is 1.0

  • struct (ndarray) – the structuring element to use for the dilation. Default is None

  • inPlace (bool) – if True, the mask is dilated in place, if False, a copy of the mask is returned. Default is True

Returns:

the dilated mask if inPlace is False, None otherwise

Return type:

Image3D

erodeMask(mask, radius=1.0, struct=None, inPlace=True)

erode a mask by a given radius

Parameters:
  • mask (Image3D) – the mask to erode

  • radius (float) – the radius of the erosion in mm. Default is 1.0

  • struct (ndarray) – the structuring element to use for the erosion. Default is None

  • inPlace (bool) – if True, the mask is eroded in place, if False, a copy of the mask is returned. Default is True

Returns:

the eroded mask if inPlace is False, None otherwise

Return type:

Image3D

gaussianSmoothing(imgArray, sigma=1, truncate=2.5, mode='reflect')

smooth an image with a gaussian filter

Parameters:
  • imgArray (ndarray) – the image to smooth

  • sigma (float) – the sigma of the gaussian filter. Default is 1

  • truncate (float) – the truncation of the gaussian filter. Default is 2.5

  • mode (str) – the mode of the gaussian filter. Default is “reflect”

Returns:

the smoothed image

Return type:

ndarray

openMask(mask, radius=1.0, struct=None, inPlace=True)

open a mask by a given radius

Parameters:
  • mask (Image3D) – the mask to open

  • radius (float) – the radius of the opening in mm. Default is 1.0

  • struct (ndarray) – the structuring element to use for the opening. Default is None

  • inPlace (bool) – if True, the mask is opened in place, if False, a copy of the mask is returned. Default is True

Returns:

the opened mask if inPlace is False, None otherwise

Return type:

Image3D

resampleCupy()

TODO

rotate3DVectorFields(vectorField, rotAnglesInDeg=[0, 0, 0], fillValue=0, outputBox='keepAll', interpOrder=1, mode='constant')

Rotate a vector field around its center

Parameters:
  • vectorField (VectorField3D) – the vector field to be rotated

  • rotationInDeg (sequence[float]) – rotation angles in degrees in the 3 directions [X, Y, Z]

  • fillValue (float) – the value to fill the data for points coming, after rotation, from outside the image. Default is 0

  • outputBox (str) – the cube in space represented by the result after rotation (same, keepAll). Default is keepAll

  • interpOrder (int) – the order of the interpolation (0, 1, 2, 3, 4) default is 1

  • mode (str) – the mode of the interpolation (constant, nearest, reflect, wrap). Default is constant

rotateData(data, rotAnglesInDeg, fillValue=0, outputBox='keepAll', interpOrder=1, mode='constant')
Parameters:
  • data (Image3D or Dynamic3DSequence or Dynamic3DModel) – data to be rotated.

  • rotAnglesInDeg (sequence[float]) – rotation angles in degrees in the 3 directions [X, Y, Z]

  • fillValue (float) – the value to fill the data for points coming, after rotation, from outside the image

  • outputBox (str) – the cube in space represented by the result after rotation

  • interpOrder (int) – the order of the interpolation

  • mode (str) – the mode of the interpolation

Return type:

data, the rotated data

rotateImage3D(image, rotAnglesInDeg=[0, 0, 0], fillValue=0, outputBox='keepAll', interpOrder=1, mode='constant')

rotate image3D around its center

Parameters:
  • image (Image3D) – the image to be rotated

  • rotAnglesInDeg (sequence[float]) – rotation angles in degrees in the 3 directions [X, Y, Z]

  • fillValue (float) – the value to fill the data for points coming, after rotation, from outside the image

  • outputBox (str) – the cube in space represented by the result after rotation

  • interpOrder (int) – the order of the interpolation

  • mode (str) – the mode of the interpolation

rotateUsingMapCoordinatesCupy(img, rotAngleInDeg, rotAxis=1)

DOES NOT WORK FOR NOW WIP :Parameters: * img

  • rotAngleInDeg

  • rotAxis

translateData(data, translationInMM, fillValue=0, outputBox='keepAll', interpOrder=1, mode='constant')
Parameters:
  • data (Image3D or Dynamic3DSequence or Dynamic3DModel)

  • translationInMM (sequence of the translation in millimeters in the 3 direction [X, Y, Z])

  • fillValue (the value to fill the data for points coming, after translation, from outside the image)

  • outputBox (the cube in space represented by the result after translation)

Return type:

the translated data

opentps.core.processing.imageProcessing.filter3D module

gaussConv(data, sigma, truncate=2.5, mode='reflect', tryGPU=True)

Apply Gaussian convolution on input data.

Parameters:
  • data (numpy array) – data to be convolved.

  • sigma (double) – standard deviation of the Gaussian.

Returns:

Convolved data.

Return type:

numpy array

normGaussConv(data, cert, sigma, tryGPU=True)

Apply normalized Gaussian convolution on input data.

Parameters:
  • data (numpy array) – data to be convolved.

  • cert (numpy array) – certainty map associated to the data.

  • sigma (double) – standard deviation of the Gaussian.

Returns:

Convolved data.

Return type:

numpy array

opentps.core.processing.imageProcessing.image2DManip module

get2DMaskCenterOfMass(maskArray)

Returns the center of mass of a 2D mask.

Parameters: - maskArray: 2D mask

getBinaryMaskFromROIDRR(drr)

Returns a binary mask from a DRR image. The mask is True where the DRR is greater than 2.

Parameters: - drr: DRR image

opentps.core.processing.imageProcessing.imageTransform3D module

applyTransform3D(data, tformMatrix: ndarray, fillValue: float = 0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0], tryGPU=False, interpOrder=1, mode='constant')

Apply a 3D transform to the data.

Parameters:
  • data (Image3D or VectorField3D) – The data to transform.

  • tformMatrix (np.ndarray) – The transform matrix.

  • fillValue (float, optional) – The value to fill the empty voxels. The default is 0.

  • outputBox (str, optional) – The output box. The default is ‘keepAll’.

  • rotCenter (list or tuple of 3 elements, optional) – The rotation center. The default is ‘dicomOrigin’.

  • translation (list or tuple of 3 elements, optional) – The translation vector in mm. The default is [0, 0, 0].

  • tryGPU (bool, optional) – Try to use the GPU. The default is False.

  • interpOrder (int, optional) – The interpolation order. The default is 1.

  • mode (str, optional) – The mode for the interpolation. The default is ‘constant’.

dicomCoordinate2iecGantry(beam: PlanIonBeam, point: Sequence[float]) Sequence[float]

Transforms a point from DICOM to IEC Gantry coordinates.

Parameters:
  • beam (PlanIonBeam) – The beam to use for the transformation.

  • point (Sequence[float]) – The point to transform coordinates [x, y, z].

Returns:

The transformed point.

Return type:

Sequence[float]

dicomToIECGantry(image: Image3D, beam: PlanIonBeam, fillValue: float = 0, cropROI: ROIContour | ROIMask | None = None, cropDim0=True, cropDim1=True, cropDim2=True) Image3D

Transforms an image from DICOM to IEC Gantry coordinates.

Parameters:
  • image (Image3D) – The image to transform.

  • beam (PlanIonBeam) – The beam to use for the transformation.

  • fillValue (float) – The value to fill the new voxels with. Default is 0.

  • cropROI (Optional[Union[ROIContour, ROIMask]]) – The ROI to crop the image to. Default is None.

  • cropDim0 (bool) – Whether to crop the image in the first dimension. Default is True.

  • cropDim1 (bool) – Whether to crop the image in the second dimension. Default is True.

  • cropDim2 (bool) – Whether to crop the image in the third dimension. Default is True.

Returns:

The transformed image.

Return type:

Image3D

extendAll(images: Sequence[Image3D], inPlace=False, fillValue: float = 0.0) Sequence[Image3D]

Extends all images to the same size and spacing, using the smallest spacing and the largest size.

Parameters:
  • images (Sequence[Image3D]) – The images to extend.

  • inPlace (bool) – Whether to modify the images in place. Default is False.

  • fillValue (float) – The value to fill the new voxels with. Default is 0.

Returns:

The extended images if inPlace is False, otherwise the original images modified.

Return type:

Sequence[Image3D]

getTtransformMatrixInPixels(transformMatrixInMM, spacing)

Get the transform matrix in pixels from a transform matrix in mm.

Parameters:
  • transformMatrixInMM (np.ndarray) – The transform matrix in mm.

  • spacing (list or tuple of 3 elements) – The spacing of the image.

Returns:

The transform matrix in pixels.

Return type:

np.ndarray

getVoxelIndexFromPosition(position, image3D)

Get the voxel index of the position given in scanner coordinates.

Parameters:
  • position (tuple or list of 3 elements in scanner coordinates) – The 3D position that will be translated into voxel indexes

  • image3D (Image3D) – The 3D image that contains its position in scanner coordinates and voxel spacing

Returns:

posInVoxels

Return type:

the 3D position as voxel indexes in the input image voxel grid

iecGantryCoordinatetoDicom(beam: PlanIonBeam, point: Sequence[float]) Sequence[float]

Transforms a point from IEC Gantry to DICOM coordinates.

Parameters:
  • beam (PlanIonBeam) – The beam to use for the transformation.

  • point (Sequence[float]) – The point to transform coordinates [x, y, z].

Returns:

The transformed point.

Return type:

Sequence[float]

iecGantryToDicom(image: Image3D, beam: PlanIonBeam, fillValue: float = 0, cropROI: ROIContour | ROIMask | None = None, cropDim0=True, cropDim1=True, cropDim2=True) Image3D

Transforms an image from IEC Gantry to DICOM coordinates.

Parameters:
  • image (Image3D) – The image to transform.

  • beam (PlanIonBeam) – The beam to use for the transformation.

  • fillValue (float) – The value to fill the image with outside the image. Default is 0.

  • cropROI (Optional[Union[ROIContour, ROIMask]]) – The ROI to crop the image to. Default is None.

  • cropDim0 (bool) – Whether to crop the image in the first dimension. Default is True.

  • cropDim1 (bool) – Whether to crop the image in the second dimension. Default is True.

  • cropDim2 (bool) – Whether to crop the image in the third dimension. Default is True.

Returns:

The transformed image.

Return type:

Image3D

parseRotCenter(rotCenterArg: Sequence[float] | str | None, image: Image3D)

Parse the rotation center.

Parameters:
  • rotCenterArg (list or tuple of 3 elements, optional) – The rotation center. The default is ‘dicomOrigin’.

  • image (Image3D) – The image.

Returns:

rotCenter – The rotation center.

Return type:

np.ndarray

rotateData(data, rotAnglesInDeg, outputBox='keepAll', fillValue=0, rotCenter='dicomOrigin', tryGPU=False, interpOrder=1, mode='constant')

Rotate the data.

Parameters:
  • data (Image3D or VectorField3D) – The data to rotate.

  • rotAnglesInDeg (list or tuple of 3 elements) – The rotation angles in degrees.

  • outputBox (str, optional) – The output box. The default is ‘keepAll’.

  • fillValue (int, optional) – The value to fill the empty voxels. The default is 0.

  • rotCenter (list or tuple of 3 elements, optional) – The rotation center. The default is ‘dicomOrigin’.

  • tryGPU (bool, optional) – Try to use the GPU. The default is False.

  • interpOrder (int, optional) – The interpolation order. The default is 1.

  • mode (str, optional) – The mode for the interpolation. The default is ‘constant’.

rotateVectorsInPlace(vectField, rotationArrayOrMatrix)

Rotate a vector field in place using a rotation matrix or a rotation vector.

Parameters:
  • vectField (VectorField3D) – The vector field to rotate.

  • rotationArrayOrMatrix (np.ndarray) – The rotation matrix or rotation vector.

transform3DMatrixFromTranslationAndRotationsVectors(transVec=[0, 0, 0], rotVec=[0, 0, 0])

Create a 4x4 affine transform matrix from a translation vector and a rotation vector.

Parameters:
  • transVec (list or tuple of 3 elements) – The translation vector in mm.

  • rotVec (list or tuple of 3 elements) – The rotation vector in degrees.

Returns:

The 4x4 affine transform matrix.

Return type:

np.ndarray

translateData(data, translationInMM, outputBox='keepAll', fillValue=0, tryGPU=False, interpOrder=1, mode='constant')

Translate the data by changing its origin.

Parameters:
  • data (Image3D or VectorField3D) – The data to translate.

  • translationInMM (list or tuple of 3 elements) – The translation vector in mm.

  • outputBox (str, optional) – The output box. The default is ‘keepAll’.

  • fillValue (int, optional) – The value to fill the empty voxels. The default is 0.

  • tryGPU (bool, optional) – Try to use the GPU. The default is False.

  • interpOrder (int, optional) – The interpolation order. The default is 1.

  • mode (str, optional) – The mode for the interpolation. The default is ‘constant’.

translateDataByChangingOrigin(data, translationInMM)

Translate the data by changing its origin.

Parameters:
  • data (Image3D or VectorField3D) – The data to translate.

  • translationInMM (list or tuple of 3 elements) – The translation vector in mm.

opentps.core.processing.imageProcessing.resampler3D module

crop3DDataAroundBox(data, box, marginInMM=[0, 0, 0])

Crop a 3D data in-place around a box given in scanner coordinates

Parameters:
  • data (Image3D, Dynamic3DModel or Dynamic3DSequence) – The 3D data that will be cropped

  • box (list of tuples or list) – Universal coordinates of the box around which the data is cropped, under the form [[x1, X2], [y1, y2], [z1, z2]]. By convention, these are coordinates of the center of the voxels at the corners of the box. The resulting cropped data inclues those voxels at the extremities.

  • marginInMM (list of float for the margin in mm for each dimension) – The margins in mm that is added around the box before cropping

resample(data: Any, spacing: Sequence[float] | None = None, gridSize: Sequence[int] | None = None, origin: Sequence[float] | None = None, fillValue: float = 0.0, outputType: dtype | None = None, inPlace: bool = False, tryGPU: bool = False)
Parameters:
  • data (Image3D, Deformation3D, Dynamic3DSequence) – The data to be resampled

  • spacing (Sequence[float]) – The new spacing of the resampled data

  • gridSize (Sequence[int]) – The new grid size of the resampled data

  • origin (Sequence[float]) – The new origin of the resampled data

  • fillValue (float) – The value to fill the resampled data with

  • outputType (np.dtype) – The data type of the resampled data

  • inPlace (bool) – Whether to perform the resampling in place

  • tryGPU (bool) – Whether to attempt to use the GPU for resampling

Returns:

resampledData – The resampled data (if inPlace = False)

Return type:

Image3D, Deformation3D, Dynamic3DSequence

resampleImage3D(image: Image3D, spacing: Sequence[float] | None = None, gridSize: Sequence[int] | None = None, origin: Sequence[float] | None = None, fillValue: float = 0.0, outputType: dtype | None = None, inPlace: bool = False, tryGPU: bool = False)
Parameters:
  • image (Image3D) – The image to be resampled

  • spacing (Sequence[float]) – The new spacing of the resampled image

  • gridSize (Sequence[int]) – The new grid size of the resampled image

  • origin (Sequence[float]) – The new origin of the resampled image

  • fillValue (float) – The value to fill the resampled image with

  • outputType (np.dtype) – The data type of the resampled image

  • inPlace (bool) – Whether to perform the resampling in place

  • tryGPU (bool) – Whether to attempt to use the GPU for resampling

Returns:

resampledImage – The resampled image (if inPlace = False)

Return type:

Image3D

resampleImage3DOnImage3D(image: Image3D, fixedImage: Image3D, fillValue: float = 0.0, inPlace: bool = False, tryGPU: bool = False)
Parameters:
  • image (Image3D) – The image to be resampled

  • fixedImage (Image3D) – The image to be resampled on

  • fillValue (float) – The value to fill the resampled image with

  • inPlace (bool) – Whether to perform the resampling in place

  • tryGPU (bool) – Whether to attempt to use the GPU for resampling

Returns:

resampledImage – The resampled image (if inPlace = False)

Return type:

Image3D

resampleOnImage3D(data: Any, fixedImage: Image3D, fillValue: float = 0.0, inPlace: bool = False, tryGPU: bool = False)
Parameters:
  • data (Image3D) – The image to be resampled

  • fixedImage (Image3D) – The image to be resampled on

  • fillValue (float) – The value to fill the resampled image with

  • inPlace (bool) – Whether to perform the resampling in place

  • tryGPU (bool) – Whether to attempt to use the GPU for resampling

Returns:

resampledImage – The resampled image (if inPlace = False)

Return type:

Image3D

resampleOpenMP(data, inputOrigin, inputSpacing, inputGridSize, outputOrigin, outputSpacing, outputGridSize, fillValue=0, outputType=None, tryGPU=True)

Resample 3D data according to new voxel grid using linear interpolation.

Parameters:
  • data (numpy array) – data to be resampled.

  • inputOrigin (list) – origin of the input data voxel grid.

  • inputSpacing (list) – spacing of the input data voxel grid.

  • inputGridSize (list) – size of the input data voxel grid.

  • outputOrigin (list) – origin of the output data voxel grid.

  • outputSpacing (list) – spacing of the output data voxel grid.

  • outputGridSize (list) – size of the output data voxel grid.

  • fillValue (scalar) – interpolation value for locations outside the input voxel grid.

  • outputType (numpy data type) – type of the output.

Returns:

Resampled data.

Return type:

numpy array

warp(data, field, spacing, fillValue=0, outputType=None, tryGPU=True)

Warp 3D data based on 3D vector field using linear interpolation.

Parameters:
  • data (numpy array) – data to be warped.

  • field (numpy array) – origin of the input data voxel grid.

  • spacing (list) – spacing of the input data voxel grid.

  • fillValue (scalar) – interpolation value for locations outside the input voxel grid.

  • outputType (numpy data type) – type of the output.

Returns:

Warped data.

Return type:

numpy array

opentps.core.processing.imageProcessing.sitkImageProcessing module

applyTransform3D(data, tformMatrix: ndarray, fillValue: float = 0.0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0])

Apply a transformation to an Image3D or a Dynamic3DSequence.

Parameters:
  • data (Union[Image3D, Dynamic3DSequence]) – The data to transform

  • tformMatrix (np.ndarray) – The transformation matrix to apply

  • fillValue (float) – The value to fill the empty voxels with. Default is 0.

  • outputBox (Union[Sequence[float], str]) – The output box to crop the transformed image to. Default is ‘keepAll’

  • rotCenter (Union[Sequence[float], str]) – The rotation center of the transformation. Default is ‘dicomOrigin’

  • translation (Sequence[float]) – The translation to apply to the image. Default is [0, 0, 0]

Returns:

The transformed data

Return type:

Union[Image3D, Dynamic3DSequence]

applyTransform3DToImage3D(image: Image3D, tformMatrix: ndarray, fillValue: float = 0.0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0])

Apply a transformation to an Image3D.

Parameters:
  • image (Image3D) – The image to transform

  • tformMatrix (np.ndarray) – The transformation matrix to apply

  • fillValue (float) – The value to fill the empty voxels with. Default is 0.

  • outputBox (Union[Sequence[float], str]) – The output box to crop the transformed image to. Default is ‘keepAll’

  • rotCenter (Union[Sequence[float], str]) – The rotation center of the transformation. Default is ‘dicomOrigin’

  • translation (Sequence[float]) – The translation to apply to the image. Default is [0, 0, 0]

Returns:

The transformed image

Return type:

Image3D

applyTransform3DToPoint(tformMatrix: ndarray, pnt: ndarray, rotCenter: Sequence[float] | None = [0, 0, 0], translation: Sequence[float] = [0, 0, 0])

Apply a transformation to a point.

Parameters:
  • tformMatrix (np.ndarray) – The transformation matrix to apply

  • pnt (np.ndarray) – The point to transform [x, y, z]

  • rotCenter (Sequence[float]) – The rotation center of the transformation. Default is [0, 0, 0]

  • translation (Sequence[float]) – The translation to apply to the image. Default is [0, 0, 0]

applyTransform3DToVectorField3D(vectField: VectorField3D, tformMatrix: ndarray, fillValue: float = 0.0, outputBox: Sequence[float] | str | None = 'keepAll', rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0])

Apply a transformation to a VectorField3D.

Parameters:
  • vectField (VectorField3D) – The vector field to transform

  • tformMatrix (np.ndarray) – The transformation matrix to apply

  • fillValue (float) – The value to fill the empty voxels with. Default is 0.

  • outputBox (Union[Sequence[float], str]) – The output box to crop the transformed image to. Default is ‘keepAll’

  • rotCenter (Union[Sequence[float], str]) – The rotation center of the transformation. Default is ‘dicomOrigin’

  • translation (Sequence[float]) – The translation to apply to the image. Default is [0, 0, 0]

Returns:

The transformed vector field

Return type:

VectorField3D

connectComponents(image: Image3D)

Connect the components of a binary image.

Parameters:

image (Image3D) – The image to connect the components of

Returns:

The connected components image

Return type:

Image3D

dilateMask(image: Image3D, radius: float | Sequence[float])

dilate a mask

Parameters:
  • image (Image3D) – The image to dilate

  • radius (Union[float, Sequence[float]]) – The radius of the dilation

Returns:

The dilated image

Return type:

Image3D

extremePoints(image: Image3D)

Get the extreme points of an Image3D (topmost, bottommost, rightmost, leftmost, … points of the object.

Parameters:

image (Image3D) – The image to get the extreme points of

Returns:

The extreme points coordinates of the image

Return type:

list

extremePointsAfterTransform(image: Image3D, tformMatrix: ndarray, rotCenter: Sequence[float] | str | None = 'dicomOrigin', translation: Sequence[float] = [0, 0, 0])

Get the extreme points of an Image3D (topmost, bottommost, rightmost, leftmost, … points of the object after applying a transformation.

Parameters:
  • image (Image3D) – The image to transform and get the extreme points of

  • tformMatrix (np.ndarray) – The transformation matrix to apply

  • rotCenter (Union[Sequence[float], str]) – The rotation center of the transformation. Default is ‘dicomOrigin’

  • translation (Sequence[float]) – The translation to apply to the image. Default is [0, 0, 0]

Returns:

The extreme points coordinates of the image after applying the transformation

Return type:

list

image2DToSITK(image: ~opentps.core.data.images._image2D.Image2D, type=<class 'numpy.float32'>)

Convert an Image2D to a SimpleITK image

Parameters:
  • image (Image2D) – The image to convert

  • type (np.dtype) – The type of the image to convert to. Default is np.float32

Returns:

The converted image

Return type:

sitk.Image

image3DToSITK(image: ~opentps.core.data.images._image3D.Image3D, type=<class 'numpy.float32'>)

Convert an Image3D to a SimpleITK image

Parameters:
  • image (Image3D) – The image to convert

  • type (np.dtype) – The type of the image to convert to. Default is np.float32

Returns:

The converted image

Return type:

sitk.Image

imageToSITK(image: ~opentps.core.data.images._image2D.Image2D | ~opentps.core.data.images._image3D.Image3D, type=<class 'numpy.float32'>)

Convert an Image2D or Image3D to a SimpleITK image

Parameters:
  • image (Image2D or Image3D) – The image to convert

  • type (np.dtype) – The type of the image to convert to. Default is np.float32

Returns:

The converted image

Return type:

sitk.Image

register(fixed_image, moving_image, multimodal=True, fillValue: float = 0.0)

Register two images.

Parameters:
  • fixed_image (Image3D) – The fixed image

  • moving_image (Image3D) – The moving image

  • multimodal (bool) – Whether the images are multimodal or not. Default is True.

  • fillValue (float) – The value to fill the empty voxels with. Default is 0.

Returns:

  • tformMatrix (np.ndarray) – The transformation matrix

  • rotcenter (np.ndarray) – The rotation center

  • Image3D – The registered image

resize(image: Image3D, newSpacing: ndarray, newOrigin: ndarray | None = None, newShape: ndarray | None = None, fillValue: float = 0.0)

Resize an Image3D

Parameters:
  • image (Image3D) – The image to resize

  • newSpacing (np.ndarray) – The new spacing of the image

  • newOrigin (np.ndarray) – The new origin of the image

  • newShape (np.ndarray) – The new shape of the image

  • fillValue (float) – The value to fill the new image with

Returns:

The resized image

Return type:

Image3D

rotateData(data, rotAnglesInDeg, fillValue=0, rotCenter='imgCenter', outputBox='keepAll')

Rotate a 3D image.

Parameters:
  • data (np.ndarray) – The image to rotate

  • rotAnglesInDeg (np.ndarray) – The rotation angles in degrees [x, y, z]

  • fillValue (float) – The value to fill the empty voxels with. Default is 0.

  • rotCenter (Union[Sequence[float], str]) – The rotation center of the transformation. Default is ‘imgCenter’

  • outputBox (Union[Sequence[float], str]) – The output box to crop the transformed image to. Default is ‘keepAll’

sitkImageToImage2D(sitkImage: ~SimpleITK.SimpleITK.Image, type=<class 'float'>)

Convert a SimpleITK image to an Image2D

Parameters:
  • sitkImage (sitk.Image) – The image to convert

  • type (np.dtype) – The type of the image to convert to. Default is np.float32

Returns:

The converted image

Return type:

Image2D

sitkImageToImage3D(sitkImage: ~SimpleITK.SimpleITK.Image, type=<class 'float'>)

Convert a SimpleITK image to an Image3D

Parameters:
  • sitkImage (sitk.Image) – The image to convert

  • type (np.dtype) – The type of the image to convert to. Default is np.float32

Returns:

The converted image

Return type:

Image3D

translateData(data, translationInMM, fillValue=0, outputBox='keepAll')

Apply a translation to a 3D image.

Parameters:
  • data (np.ndarray) – The image to translate

  • translationInMM (np.ndarray) – The translation in mm [x, y, z]

  • fillValue (float) – The value to fill the empty voxels with. Default is 0.

  • outputBox (Union[Sequence[float], str]) – The output box to crop the transformed image to. Default is ‘keepAll’

opentps.core.processing.imageProcessing.syntheticDeformation module

applyBaselineShift(inputData, ROI, shift, sigma=2, tryGPU=True)

apply a baseline shift to the image and the ROI

Parameters:
  • inputData (Dynamic3DModel or Image3D) – the image to deform

  • ROI (ROIContour or ROIMask) – the ROI to deform

  • shift (np.array) – the shift to apply in mm

  • sigma (float) – the sigma of the gaussian used to smooth the deformation

  • tryGPU (bool) – if True, try to use the GPU

Returns:

  • Dynamic3DModel or Image3D – the deformed image

  • ROIContour or ROIMask – the deformed ROI

forceShiftInMask(deformation, mask, shift)

force the deformation to be 0 in the mask

Parameters:
  • deformation (Deformation3D) – the deformation to modify

  • mask (ROIMask) – the mask to use

  • shift (np.array) – the shift to apply (same as the one applied to the image)

Returns:

the modified deformation

Return type:

Deformation3D

shrinkOrgan(model, organMask, shrinkSize=[2, 2, 2], tryGPU=True)

shrink the organ mask by a given size

Parameters:
  • model (Dynamic3DModel) – the model to modify

  • organMask (ROIMask) – the organ mask to shrink

  • shrinkSize (list) – the size of the shrink in mm in each direction (x, y, z)

  • tryGPU (bool) – if True, try to use the GPU

Returns:

  • Dynamic3DModel – the modified model

  • ROIMask – the modified organ mask

Module contents