opentps.core.processing.deformableDataAugmentationToolBox package

Submodules

opentps.core.processing.deformableDataAugmentationToolBox.BreathingSignalGeneration module

Created on Wed Feb 16 08:43:30 2022

@author: grotsartdehe

events(L, meanDurationEvents, varianceDurationEvents, Tend)

Generate the timestamps of the events.

Parameters:
  • L (float) – parameter of the exponential distribution.

  • meanDurationEvents (float) – mean duration of the events.

  • varianceDurationEvents (float) – variance of the duration of the events.

  • Tend (float) – duration of the signal.

Returns:

timestamp – list of the timestamps of the events.

Return type:

list

signal2DGeneration(amplitude=20, period=4.0, mean=0, sigma=3, step=0.5, signalDuration=100, coeffMin=0.1, coeffMax=0.45, meanEvent=0.05, meanEventApnea=0.008333333333333333, otherDimensionsRatio=[0.3, 0.4], otherDimensionsNoiseVar=[0.1, 0.05])

Generate a 2D breathing signal.

Parameters:
  • amplitude (float) – amplitude of the breathing signal. default is 20.

  • period (float) – period of the breathing signal. default is 4.0.

  • mean (float) – mean of the noise. default is 0.

  • sigma (float) – standard deviation of the noise. default is 3.

  • step (float) – step between two timestamps. default is 0.5.

  • signalDuration (float) – duration of the signal. default is 100.

  • coeffMin (float) – minimum coefficient of the breathing signal. default is 0.10.

  • coeffMax (float) – maximum coefficient of the breathing signal. default is 0.45.

  • meanEvent (float) – mean of the event. default is 1/20.

  • meanEventApnea (float) – mean of the apnea event. default is 1/120.

  • otherDimensionsRatio (list) – list of the ratio of the other dimensions. default is [0.3, 0.4].

  • otherDimensionsNoiseVar (list) – list of the noise variance of the other dimensions. default is [0.1, 0.05].

Returns:

  • timestamps (array) – timestamps of the signal.

  • signal2D (array) – 2D breathing signal.

signal3DGeneration(amplitude=20, period=4.0, mean=0, sigma=3, step=0.5, signalDuration=100, coeffMin=0.1, coeffMax=0.45, meanEvent=0.05, meanEventApnea=0.008333333333333333, otherDimensionsRatio=[0.3, 0.4], otherDimensionsNoiseVar=[0.1, 0.05])

Generate a 3D breathing signal.

Parameters:
  • amplitude (float) – amplitude of the breathing signal. default is 20.

  • period (float) – period of the breathing signal. default is 4.0.

  • mean (float) – mean of the noise. default is 0.

  • sigma (float) – standard deviation of the noise. default is 3.

  • step (float) – step between two timestamps. default is 0.5.

  • signalDuration (float) – duration of the signal. default is 100.

  • coeffMin (float) – minimum coefficient of the breathing signal. default is 0.10.

  • coeffMax (float) – maximum coefficient of the breathing signal. default is 0.45.

  • meanEvent (float) – mean of the event. default is 1/20.

  • meanEventApnea (float) – mean of the apnea event. default is 1/120.

  • otherDimensionsRatio (list) – list of the ratio of the other dimensions. default is [0.3, 0.4].

  • otherDimensionsNoiseVar (list) – list of the noise variance of the other dimensions. default is [0.1, 0.05].

Returns:

  • timestamps (array) – timestamps of the signal.

  • signal3D (array) – 3D breathing signal.

signalGeneration(amplitude=10, period=4.0, mean=0, sigma=3, step=0.5, signalDuration=100, coeffMin=0.1, coeffMax=0.15, meanEvent=0.05, meanEventApnea=0.008333333333333333)

Generate the breathing signal.

Parameters:
  • amplitude (float) – amplitude of the signal. default is 10.

  • period (float) – period of the signal. default is 4.0.

  • mean (float) – mean of the noise. default is 0.

  • sigma (float) – standard deviation of the noise. default is 3.

  • step (float) – step of the timestamps. default is 0.5.

  • signalDuration (float) – duration of the signal. default is 100.

  • coeffMin (float) – minimum value of the coefficient of the variation of the amplitude and the frequency. default is 0.10.

  • coeffMax (float) – maximum value of the coefficient of the variation of the amplitude and the frequency. default is 0.15.

  • meanEvent (float) – mean of the duration of the events. default is 1/20.

  • meanEventApnea (float) – mean of the duration of the apnea events. default is 1/120.

Returns:

  • timestamps (array) – timestamps of the signal.

  • signal (array) – breathing signal.

vectorSimulation(coeffMin, coeffMax, amplitude, frequency, timestamps, listOfEvents)

Generate the amplitude and the frequency of the signal.

Parameters:
  • coeffMin (float) – minimum value of the coefficient of the variation of the amplitude and the frequency.

  • coeffMax (float) – maximum value of the coefficient of the variation of the amplitude and the frequency.

  • amplitude (float) – amplitude of the signal.

  • frequency (float) – frequency of the signal.

  • timestamps (array) – timestamps of the signal.

  • listOfEvents (list) – list of the timestamps of the events.

Returns:

  • y_amplitude (array) – amplitude of the signal.

  • y_frequency (array) – frequency of the signal.

opentps.core.processing.deformableDataAugmentationToolBox.generateDynamicSequencesFromModel module

computePhaseRatio(sampleValuePos, CTPhasesSubPart, CTPhasesPartsIndexes, ascendDescendCase, meanPos)

given a sample value position, the CT phases positions, the CT phases indexes, the ascent or descent case and the mean position, compute the phase ratio

Parameters:
  • sampleValuePos (float) – the sample value position

  • CTPhasesSubPart (1D numpy array) – the CT phases positions

  • CTPhasesPartsIndexes (1D numpy array) – the CT phases indexes

  • ascendDescendCase (str) – ‘ascending’ or ‘descending’

  • meanPos (float) – the mean position

Returns:

  • [interExtraCase, phaseIndex, correctedPhaseIndex] (list)

  • with

    interExtraCasestr

    ’I’ or ‘E’ meaning inter or extra

    phaseIndexint

    the phase index

    correctedPhaseIndexfloat

    the phase ratio

    phaseRatiofloat

    the phase ratio

generateDeformationListFromBreathingSignalsAndModel(model, signalList, ROIList, signalIdxUsed=[0, 0], dimensionUsed='Z', outputType=<class 'numpy.float32'>, tryGPU=True)

Generate a list of deformation fields from a model, in which each given ROI follows its breathing signal

Parameters:
  • model (Dynamic3DModel) – The dynamic 3D model that will be used to create the images of the resulting sequence

  • signalList (list) – list of breathing signals as 1D numpy arrays

  • ROIList (list) – list of points as [X, Y, Z] or (X, Y, Z) –> does not work with ROI’s as masks or struct

  • dimensionUsed (str) – X, Y, Z or norm, the dimension used to compare the breathing signals with the model deformation values

  • outputType (pixel data type (np.float32, np.uint16, etc))

Returns:

a list of deformation fields

Return type:

deformationList (list)

generateDynSeqFromBreathingSignalsAndModel(model, signalList, ROIList, signalIdxUsed=[0, 0], dimensionUsed='Z', outputType=<class 'numpy.float32'>, tryGPU=True)

Generate a dynamic 3D sequence from a model, in which each given ROI follows its breathing signal

Parameters:
  • model (Dynamic3DModel) – The dynamic 3D model that will be used to create the images of the resulting sequence

  • signalList (list) – list of breathing signals as 1D numpy arrays

  • ROIList (list) – list of points as [X, Y, Z] or (X, Y, Z) –> does not work with ROI’s as masks or struct

  • dimensionUsed (str) – X, Y, Z or norm, the dimension used to compare the breathing signals with the model deformation values

  • outputType (pixel data type (np.float32, np.uint16, etc))

Returns:

dynseq (Dynamic3DSequence)

Return type:

a new sequence containing the generated images

getPhaseValueList(ROI, model, signal, signalIdxUsed, dimensionUsed='Z', tryGPU=True)

Get the phase value list for a given ROI and a given model

Parameters:
  • ROI (list) – list of points of the ROI as [X, Y, Z] or (X, Y, Z) –> does not work with ROI’s as masks or struct

  • model (Dynamic3DModel) – The dynamic 3D model that will be used to create the images of the resulting sequence

  • signal (1D numpy array) – the breathing signal

  • signalIdxUsed (list) – the indexes of the signal to use

  • dimensionUsed (str) – X, Y, Z or norm, the dimension used to compare the breathing signals with the model deformation values

Returns:

a list of phase values for each sample of the breathing signal

Return type:

phaseValueList (list)

isAscentOrDescentCase(signal, currentIndex)

given a signal and a current index, return if the current index is in an ascent or descent case

Parameters:
  • signal (1D numpy array) – the breathing signal

  • currentIndex (int) – the current index of the signal

Returns:

ascendDescendCase – ‘ascending’ or ‘descending’

Return type:

str

splitAscentDescentSubsets(CTPhasePositions)

Split the CTPhasePositions into ascent and descent subsets

Parameters:

CTPhasePositions (1D numpy array) – the CT phase positions

Returns:

  • ascentPart (1D numpy array) – the CT phase positions of the ascent subset

  • ascentPartIndexes (1D numpy array) – the indexes of the ascent subset

  • descentPart (1D numpy array) – the CT phase positions of the descent subset

  • descentPartIndexes (1D numpy array) – the indexes of the descent subset

  • amplitude (float) – the amplitude of the CT phase positions

opentps.core.processing.deformableDataAugmentationToolBox.generateRandomSamplesFromModel module

generateRandomDeformationsFromModel(model, numberOfSamples=1, amplitudeRange=[0.8, 1.2], ampDistribution='uniform')

generate random deformations from a model

Parameters:
  • model (DeformableModel) – the model to generate the deformations from

  • numberOfSamples (int) – number of deformations to generate

  • amplitudeRange (list of 2 floats) – range of the amplitude of the deformation

  • ampDistribution (string) – distribution of the amplitude of the deformation

Returns:

sampleDeformationList – list of the generated deformations

Return type:

list of Deformation

generateRandomImagesFromModel(model, numberOfSamples=1, amplitudeRange=[0.8, 1.2], ampDistribution='uniform', tryGPU=True, outputType=<class 'numpy.int16'>)

generate random images from a model

Parameters:
  • model (DeformableModel) – the model to generate the images from

  • numberOfSamples (int) – number of images to generate

  • amplitudeRange (list of 2 floats) – range of the amplitude of the deformation

  • ampDistribution (string) – distribution of the amplitude of the deformation

  • tryGPU (bool) – try to use the GPU

  • outputType (numpy type) – type of the output image

Returns:

sampleImageList – list of the generated images

Return type:

list of numpy arrays

opentps.core.processing.deformableDataAugmentationToolBox.interFractionChanges module

opentps.core.processing.deformableDataAugmentationToolBox.modelManipFunctions module

getAverageFieldValueAroundPosition(position, field, dimensionUsed='Z')

Get the average values in the specified dimension around the given position in the given field.

Parameters:
  • position (tuple or list of 3 elements) – The 3D position around which the 3x3x3 field values are extracted

  • field (VectorField3D) – The 3D vector field from which the data is extracted

  • dimensionUsed (str) – X, Y, Z or norm, the dimension extracted from the 3D vector field

Returns:

  • usedValue (float) (the average deformation value on the 3X3X3 cube in the specified dimension around the field)

  • speficied position

getAverageModelValuesAroundPosition(position, model, dimensionUsed='Z', tryGPU=True)

Get the average values in the specified dimension around the given position for each field in a Dynamic3DModel.

Parameters:
  • position (tuple or list of 3 elements) – The 3D position at which the fields values are extracted

  • model (Dynamic3DModel) – The dynamic 3D model containing the deformation fields

  • dimensionUsed (str) – X, Y, Z or norm, the dimension extracted from the deformation fields

Returns:

  • modelDefValuesArray (np.ndarray) (the average deformation values on the 3X3X3 cube in the specified dimension)

  • around the speficied position for each field in the deformation model

getFieldValueAtPosition(position, field, dimensionUsed='Z')

Get the field value in the specified dimension at the given position in the given field. Alternative function to getAverageFieldValueAroundPosition. This one does not compute an average on a 3x3x3 cube around the position but gets the exact position value.

Parameters:
  • position (tuple or list of 3 elements) – The 3D position at which the field value is extracted

  • field (VectorField3D) – The 3D vector field from which the data is extracted

  • dimensionUsed (str) – X, Y, Z or norm, the dimension extracted from the 3D vector field

Returns:

usedValue (float)

Return type:

the deformation value in the specified dimension at the field speficied position

opentps.core.processing.deformableDataAugmentationToolBox.multiProcSpawnMethods module

deformImageAndMask(img, ROIMask, deformation, tryGPU=True, GPUNumber=0)

This function is specific to this example and used to : - deform a CTImage and an ROIMask, - compute the deformed mask 3D center of mass - create DRR’s for both, - binarize the DRR of the ROIMask - compute the 2D center of mass for the ROI DRR

multiProcDeform(deformationList, dynMod, GTVMask, ncore=None, GPUNumber=0)

Deform images and masks in parallel using multiprocessing.spawn method.

Parameters:
  • deformationList (list of Deformation objects) – List of Deformation objects containing the deformation fields.

  • dynMod (CTImage object) – CTImage object to deform.

  • GTVMask (ROIMask object) – ROIMask object to deform.

  • ncore (int, optional) – Number of logical cores to use. If None, all logical cores are used. The default is None.

  • GPUNumber (int, optional) – Number of the GPU to use. If None, the CPU is used. The default is 0.

Returns:

resultDeformImageAndMask – List of deformed CTImage and ROIMask objects.

Return type:

list of CTImage and ROIMask objects

opentps.core.processing.deformableDataAugmentationToolBox.weightMaps module

createExternalPoints(imgSize, numberOfPointsPerEdge=0)

Create a list of points that are outside the image, to be used for the weight maps

Parameters:
  • imgSize (list) – size of the image

  • numberOfPointsPerEdge (int) – number of points to create per edge of the image. default is 0, which means no points are created.

Returns:

externalPoints – list of points that are outside the image

Return type:

list

createWeightMaps(absoluteInternalPoints, imageGridSize, imageOrigin, pixelSpacing)

Create a list of weight maps, one for each internal point. Each weight map is a 3D array of the same size as the image, with values between 0 and 1. The value 1 is at the position of the internal point, and the value 0 is at the position of the external points.

Parameters:
  • absoluteInternalPoints (list) – list of internal points coordinates in absolute coordinates

  • imageGridSize (list) – size of the image

  • imageOrigin (list) – origin of the image

  • pixelSpacing (list) – pixel spacing of the image

Returns:

weightMapList – list of weight maps

Return type:

list

generateDeformationFromTrackers(midpModel, phases, amplitudes, internalPoints)

Generate a deformation field from a list of internal points, phases and amplitudes.

Parameters:
  • midpModel (MidPositionModel) – mid-position model

  • phases (list) – list of phases

  • amplitudes (list) – list of amplitudes

  • internalPoints (list) – list of internal points coordinates in absolute coordinates

Returns:

  • field (Image3D) – deformation field

  • weightMapList (list) – list of weight maps

generateDeformationFromTrackersAndWeightMaps(midpModel, phases, amplitudes, weightMapList)

generate a deformation field from a list of weight maps, phases and amplitudes.

Parameters:
  • midpModel (MidPositionModel) – mid-position model

  • phases (list) – list of phases

  • amplitudes (list) – list of amplitudes

  • weightMapList (list) – list of weight maps

Returns:

field – deformation field

Return type:

Image3D

getWeightMapsAsImage3DList(internalPoints, ref3DImage)

Create a list of weight maps, one for each internal point. Each weight map is a 3D array of the same size as the image, with values between 0 and 1.

Parameters:
  • internalPoints (list) – list of internal points coordinates in absolute coordinates

  • ref3DImage (Image3D) – reference image

Returns:

image3DList – list of weight maps as Image3D objects

Return type:

list

showPoints(pointList)

Show a list of points in a plot.

Parameters:

pointList (list) – list of points coordinates

Module contents