Image Analysis
A collection of useful functions for image analysis, implemented in the fredtools.ImgAnalyse subpackage. The image must be an instance of a SimpleITK image.
Image analysis
- fredtools.getExtent(img: Image, displayInfo: bool = False) tuple[tuple[float, float], ...]
Get the extent of an image.
The function calculates the extent of an image, which is defined as the coordinates of the most side voxels’ borders in each direction. The extent is assumed to be in millimeters.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – If True, a summary of the function results will be displayed. (def. False)
- Returns:
A tuple of extent values in the form ((xmin, xmax), (ymin, ymax), …)
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getExtMplGet the extent of a SimpleITK image object describing a slice in matplotlib format.
- fredtools.getSize(img: Image, displayInfo: bool = False) tuple[float, ...]
Get the size of an image.
This function calculates the size of an image in each direction. The size is defined as the absolute difference of the image extent. It is assumed that the coordinate system is in millimeters.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – If True, displays a summary of the function results. (def. False)
- Returns:
A tuple of sizes in each direction in the form (xSize, ySize, …)
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getExtentGet the extent of an image.
- fredtools.getImageCenter(img: Image, displayInfo: bool = False) tuple[float, ...]
Get the center of an image.
The function calculates the center of an image defined as a SimpleITK image object in each direction. It is assumed that the coordinate system is in [mm].
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A Tuple of image center coordinates in form (xCenter,yCenter,…)
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getMassCenterget the center of mass of an image.
getMaxPositionget the position of an image maximum.
getMinPositionget the position of an image minimum.
- fredtools.getMassCenter(img: Image, displayInfo: bool = False) tuple[float, ...]
Get the center of mass of an image.
The function calculates the center of mass of an image defined as a SimpleITK image object in each direction. It is assumed that the coordinate system is in [mm]. Any NaN values are replaced with zeros.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A tuple of image center of mass coordinates in form (xMassCenter,yMassCenter,…)
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getImageCenterget the center of an image.
getMaxPositionget the position of an image maximum.
getMinPositionget the position of an image minimum.
- fredtools.getMaxPosition(img: Image, displayInfo: bool = False) tuple[float, ...]
Get the maximum position of an image.
The function calculates the position of the maximum voxel of an image defined as a SimpleITK image object. It is assumed that the coordinate system is in [mm].
- Parameters:
img (SimpleITK Image) – The object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A Tuple of image maximum voxel coordinates in form (xPosition,yPosition,…).
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getImageCenterget the center of an image.
getMassCenterget the center of mass of an image.
getMinPositionget the position of an image minimum.
- fredtools.getMinPosition(img: Image, displayInfo: bool = False) tuple[float, ...]
Get the minimum position of an image.
The function calculates the position of the minimum voxel of an image defined as a SimpleITK image object. It is assumed that the coordinate system is in [mm].
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A Tuple of image minimum voxel coordinates in form (xPosition,yPosition,…).
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getImageCenterget the center of an image.
getMassCenterget the center of mass of an image.
getMaxPositionget the position of an image maximum.
- fredtools.getVoxelCenters(img: Image, displayInfo: bool = False) tuple[tuple[float, ...], ...]
Get voxel centers.
The function gets voxels’ centers in each direction of an image defined as a SimpleITK image object. It is assumed that the coordinate system is in [mm].
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A tuple of tuples with voxels’ centers in each direction in form ([x0,x1,…],[y0,y1,…],…)
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getVoxelEdgesget voxel edges.
- fredtools.getVoxelEdges(img: Image, displayInfo: bool = False) tuple[tuple[float, ...], ...]
Get voxel edges.
The function gets voxels’ edges in each direction of an image defined as a SimpleITK image object. It is assumed that the coordinate system is in [mm].
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A tuple of tuples with voxels’ edges in each direction in form ([x0,x1,…],[y0,y1,…],…)
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getVoxelCentersget voxel centers.
- fredtools.getVoxelPhysicalPoints(img: Image, insideMask: bool = False, displayInfo: bool = False) NDArray
Get physical positions of voxels.
The function gets voxels’ physical positions of an image defined as a SimpleITK image object. If the image is a binary mask, then the voxel positions only inside the mask can be requested with insideMask parameter, otherwise all voxels’ positions will be returned.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
insideMask (bool, optional) – Determine if only the voxels’ positions inside the mask should be returned. The img must describe a binary mask. (def. False)
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A numpy array of size NxD of float64 voxel positions, where N is the number of voxels and D is the dimension. The positions are equal to those of SimpleITK TransformIndexToPhysicalPoint, ordered with x fastest.
- Return type:
NxD numpy.array
- Raises:
TypeError – If img is not an instance of a SimpleITK image, or if insideMask is True and img does not describe a binary mask.
See also
getVoxelCentersget voxel centers.
createImgFromFunctioncreate an image from a function of the voxel centers.
- fredtools.getVoxelCentersGrid(img: Image, displayInfo: bool = False) tuple[NDArray, ...]
Get physical positions of voxel centers as a grid.
The function gets the physical positions of the centers of all voxels of an image defined as a SimpleITK image object, as one array for each physical coordinate (x, y, z, …). Each array has the numpy shape of the image, so that it can be used directly together with the array of the image values given by the SimpleITK GetArrayFromImage function, for instance to calculate a function of the positions for each voxel or to select the positions of the voxels with a mask. It is assumed that the coordinate system is in [mm].
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A tuple of D float64 numpy arrays, where D is the dimension of the image, in form (X, Y, Z, …), i.e. the first array holds the x coordinates. Each array has the numpy shape of the image, which is the reversed size of the image, e.g. (nz, ny, nx) for a 3D image. The element [k, j, i] of each array is the coordinate of the center of the voxel with the index (i, j, k). The arrays are read-only.
- Return type:
tuple of numpy.array
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getVoxelCentersget voxel centers in each direction.
getVoxelPhysicalPointsget physical positions of voxels as a list of points.
createImgFromFunctioncreate an image from a function of the voxel centers.
arrget the array of the image values without the axes of a single voxel.
Notes
The positions are calculated in float64 precision with the same formula as in SimpleITK, i.e. origin + direction * spacing * index, therefore, they are equal to the positions given by getVoxelPhysicalPoints or by the SimpleITK TransformIndexToPhysicalPoint function, also for the images with a non-identity direction.
For an image with the axes along the axes of the coordinate system (an identity or a flipped direction), each coordinate changes along one axis of the image only. The arrays are then views repeating a single row of values (see numpy.broadcast_to), which need almost no memory. For a rotated image, each array needs 8 bytes per voxel. The arrays cannot be modified. Use numpy.array to get a copy that can be modified.
The arrays have the shape of the array given by the SimpleITK GetArrayFromImage function. The function arr gives the array of the image values without the axes of a single voxel, therefore, for an image describing a slice or a profile, its shape is different.
Examples
Let’s assume that the img is a 2D image with 4 voxels of 2 mm in X direction, starting at 10 mm, and with 3 voxels of 5 mm in Y direction, starting at 100 mm. The numpy shape of the image is (3, 4).
>>> X, Y = fredtools.getVoxelCentersGrid(img) >>> X array([[10., 12., 14., 16.], [10., 12., 14., 16.], [10., 12., 14., 16.]]) >>> Y array([[100., 100., 100., 100.], [105., 105., 105., 105.], [110., 110., 110., 110.]])
Calculate the distance of each voxel from the point [12, 105] and get the positions and the values of the voxels closer than 4 mm to the point.
>>> distance = numpy.sqrt((X - 12)**2 + (Y - 105)**2) >>> X[distance < 4] array([10., 12., 14.]) >>> Y[distance < 4] array([105., 105., 105.]) >>> values = SimpleITK.GetArrayFromImage(img)[distance < 4]
- fredtools.getExtMpl(img: Image) tuple[float, float, float, float]
Get the extent of a slice in a format consistent with imshow of matplotlib module.
The function gets the extent of an image defined as a SimpleITK image object describing a slice. Extent means the coordinates of the most side pixels’ borders in each direction and are returned in format (left, right, bottom, top), which is consistent with the
extentoptional parameter ofimshowofmatplotlib.pyplotmodule.- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image describing a slice.
- Returns:
A tuple of extent values in the form (left, right, bottom, top).
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image describing a slice.
See also
Examples
Assuming that the img is describing a slice (e.g. the shape is [100,1,300,1]), the line:
>>> matplotlib.pyplot.imshow(fredtools.arr(img), extent=fredtools.getExtMpl(img))
will display a 2D image of the shape 100x300 px in real coordinates.
- fredtools.isPointInside(img: Image, point: Iterable[int | float | number] | Iterable[Iterable[int | float | number]], displayInfo: bool = False) bool | tuple[bool, ...]
Check if a point or a list of points is inside the extent of an image.
This function checks if a point or a list of points are inside the extent of an image defined as a SimpleITK image object. The check is done along the axes of the image, therefore, it is valid also for an image with a non-identity direction (flipped or rotated). The points at the border of the image are considered to be inside the image.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
point (Iterable[float] | Iterable[Iterable[float]]) – An iterable (numpy array, list of lists, etc) of N points. Every point must be of the image dimension size.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A single boolean value if a single point is provided, or a tuple of boolean values if a list of points is provided.
- Return type:
bool | tuple[bool, …]
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
ValueError – If point is not a point or a list of points of the image dimension size.
See also
getExtentGet the extent of the image in each direction.
transformPhysicalPointToContinuousIndextransform physical points to continuous indices.
Notes
A point is inside the image when its continuous index is from -0.5 to N-0.5 along every axis of the image, where N is the number of voxels along the axis. The continuous indices are calculated in floating-point arithmetic, therefore, a point lying exactly at the border of the image can be found outside the image, depending on the rounding.
Examples
Let’s assume that the img is a 3D image with extent:
>>> fredtools.getExtent(img) ((-175.0, 174.3), (-354.6, -70.9), (-786.2, -524.6))
It means that the img expands from -175.0 to 174.3, from -354.6 to -70.9, and from -786.2 to -524.6 in the X, Y, and Z directions, respectively. Let’s check if the point [0,0,0] and a list of points [[0,0,0],[0,-100,-600],[-170,-350,-780]] are inside the image extent:
>>> fredtools.isPointInside(img, [0,0,0]) False >>> fredtools.isPointInside(img, [[0,0,0],[0,-100,-600],[-170,-350,-780]]) (False, True, True)
- fredtools.getStatistics(img: Image, displayInfo: bool = False) StatisticsImageFilter
Get statistics of image
The function gets basic statistics of an image defined as a SimpleITK image object. It is a wrapper for SimpleITK.StatisticsImageFilter routine executed on the image. If the image is a vector image, it is silently converted to a scalar image being the sum of the vector components (with fredtools.sumVectorImg) and a warning is logged; the statistics are then calculated for the sum of vectors.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
SimpleITK image filter with image statistics.
- Return type:
SimpleITK filter
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
SimpleITK.StatisticsImageFiltermore about possible statistics.
Examples
It is assumed that the image is a 3D dose distribution. Some statistics of the image, like the mean, standard deviation or sum can be calculated.
>>> stat=fredtools.getStatistics(img) >>> stat.GetMean() -732.6387321958799 >>> stat.GetSigma() 468.4351857326367 >>> stat.GetSum() -33870013138.0
- fredtools.getIntegral(img: Image, displayInfo: bool = False) int | float | number
Get integral of image
The function calculates the integral of an image defined as a SimpleITK image object. The integral is calculated as the sum of all voxel values multiplied by the voxel volume, where the voxel volume is the product of the image spacing (assumed to be in mm), hence the integral is expressed in the voxel value units times mm³. If the image is a vector image, it is converted to a scalar image being the sum of the vector components (with fredtools.sumVectorImg) and a warning is logged; the integral is then calculated for the sum of vectors.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A float value with the integral of the image.
- Return type:
float
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getStatisticsget basic statistics of the image.
- fredtools.getStructVolume(imgMask: Image, displayInfo: bool = False) float
Get volume of a structure mask
The function calculates the volume of a structure described by a binary or a floating mask defined as a SimpleITK image object. The volume is the integral of the mask (see fredtools.getIntegral), i.e. the sum of the voxel values multiplied by the voxel volume, where the image spacing is assumed to be in mm, and it is expressed in cm³. For a floating mask, the voxel values describe the fractional occupancy of the voxels by the structure, hence the partial volumes of the voxels at the structure border are taken into account. If the mask holds the ‘ROIName’ metadata (as the masks produced by fredtools.mapStructToImg do), the structure name is included in the displayed summary.
- Parameters:
imgMask (SimpleITK Image) – An object of a SimpleITK image describing a binary or a floating mask.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A float value with the volume of the structure in cm³.
- Return type:
float
- Raises:
TypeError – If imgMask is not an instance of a SimpleITK image describing a binary or a floating mask.
See also
getIntegralget the integral of an image.
mapStructToImgmap a structure from an RS dicom to an image, producing a mask.
getDVHMaskcalculate the DVH of a mask, including its volume.
- fredtools.compareImg(img1: Image, img2: Image, decimal: int = 3, displayInfo: bool = False) bool
Compare two images pixel by pixel.
The function gets two images defined as instances of a SimpleITK image object and compares them pixel by pixel. The comparison is done with a given decimal tolerance.
- Parameters:
img1 (SimpleITK Image) – An object of a SimpleITK image.
img2 (SimpleITK Image) – An object of a SimpleITK image.
decimal (int, optional) – The number of decimal places to compare the images. (def. 3)
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A true/false value describing if the images are the same in the sense of the pixel values.
- Return type:
bool
- Raises:
TypeError – If img1 or img2 is not an instance of a SimpleITK image.
- fredtools.compareImgFoR(img1: Image, img2: Image, decimal: int = 3, displayInfo: bool = False) bool
Compare two images frame of reference
The function gets two images defined as instances of a SimpleITK image object and compares the frame of reference, i.e. dimension, size, origin, spacing and direction.
- Parameters:
img1 (SimpleITK Image) – An object of a SimpleITK image.
img2 (SimpleITK Image) – An object of a SimpleITK image.
decimal (int, optional) – Use rounding to a given number of decimals when comparing origin and spacing. (def. 3)
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A true/false value describing if the images are the same in the sense of the frame of reference.
- Return type:
bool
- Raises:
TypeError – If img1 or img2 is not an instance of a SimpleITK image.
See also
compareImgcompare two images voxel by voxel.
compareImgFoROverlapcheck if the frames of reference of two images overlap.
- fredtools.compareImgFoROverlap(img1: Image, img2: Image, decimal: int = 3, displayInfo: bool = False) bool
Check if the frames of reference of two images overlap.
The function gets two images defined as instances of a SimpleITK image object and checks if the volumes occupied by the images, i.e. the boxes enclosed by the outer edges of their voxels, overlap at least partially. The images can have different size, spacing, origin and direction, but they must have the same dimension. Images that only touch each other (with a common face, edge or corner but no common volume) are considered detached.
- Parameters:
img1 (SimpleITK Image) – An object of a SimpleITK image.
img2 (SimpleITK Image) – An object of a SimpleITK image.
decimal (int, optional) – Use rounding to a given number of decimals of the overlap depth. (def. 3)
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
A true/false value describing if the frames of reference of the images overlap at least partially.
- Return type:
bool
- Raises:
TypeError – If img1 or img2 is not an instance of a SimpleITK image.
ValueError – If img1 and img2 have different dimensions.
See also
compareImgFoRcompare two images frame of reference.
Notes
The overlap is determined by the overlap depth, i.e. the radius of the largest sphere (circle for 2D images) that fits inside both images, found with linear programming (
scipy.optimize.linprog). The images overlap if the overlap depth, given in the same length unit as the images (in [mm] by default) and rounded to decimal decimals, is positive. It is zero for touching images and negative for detached images. The method is exact for images of any dimension and any direction matrices.
- fredtools.pos(img: Image) tuple[float, ...] | tuple[tuple[float, ...], ...]
Get voxels’ centers for axes of the size different than one.
The function calculates the voxels’ centers of an image defined as a SimpleITK image object in each direction, only for those axes for which the size is more than one. The function is useful for plotting profiles.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
- Returns:
A tuple with voxels’ centers for the image describing a profile (the size in only one direction is greater than one) or list of tuples for all directions for which the size is greater than one.
- Return type:
tuple or list of tuples
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
getVoxelCentersget voxels’ centers of the image in each direction.
vecget a vector with values for the image describing a profile.
Examples
Let’s assume that the img is a 3D image describing a profile, so is of size [1,200,1]. It is possible to get the voxels’ centers only in the Y direction:
>>> fredtools.pos(img) (-174.658203125, -173.974609375, ... )
This can be used for plotting profiles. The line:
>>> matplotlib.pyplot.plot(fredtools.pos(img), fredtools.vec(img))
will plot the profile in the Y direction of the image.
- fredtools.arr(img: Image) NDArray
Get squeezed array from image.
The function gets a squeezed array (with no unitary dimensions) from an image defined as a SimpleITK image object. This can be used for plotting
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
- Returns:
A numpy array with no unitary dimensions.
- Return type:
numpy array
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
See also
Examples
Assuming that the img is describing a slice (e.g. the shape is [100,1,300,1]), the line:
>>> matplotlib.pyplot.imshow(fredtools.arr(img), extent=fredtools.getExtMpl(img))
will display a 2D image of the shape 100x300 px in real coordinates.
- fredtools.vec(img: Image) NDArray
Get 1D array from image describing a profile.
The function gets a squeezed (with no unitary dimensions), 1D array from an image defined as a SimpleITK image object describing a profile. This can be used for plotting
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image describing a profile.
- Returns:
A 1D numpy array.
- Return type:
numpy array
- Raises:
TypeError – If img is not an instance of a SimpleITK image describing a profile.
See also
Examples
Assuming that the img is describing a profile (e.g. the shape is [1,1,300,1]), the line:
>>> matplotlib.pyplot.plot(fredtools.pos(img), fredtools.vec(img))
will plot the profile in the Z direction of the image.
Image information
- fredtools.displayImageInfo(img: Image, metadata: bool = True) None
Display some image information.
The function displays information about an image given as a SimpleITK image object. The information is logged with the module logger at the INFO level.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
metadata (bool, optional) – Display additional metadata. (def. True)
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
Notes
The function sets the level of the module logger to INFO as a side effect, so that the image information is always displayed, regardless of the logging level configured before the call.
Examples
Reading image from file and displaying the image information.
>>> imgCT=fredtools.readMHD('CT.mhd') >>> fredtools.displayImageInfo(imgCT) displayImageInfo: Image info: 3D image describing a volume (3D) dims (xyz) = [511 415 218] voxel size [mm] = [0.68359375 0.68359375 1.2 ] origin [mm] = [-174.65820312 -354.28710938 -785.6 ] x-spatial voxel center [mm] = [ -174.658203, -173.974609, ..., 173.291016, 173.974609 ] ... data type: 16-bit signed integer range: from -1024 to 3071 ...
The same can be displayed when reading the image with displayInfo=True, for instance:
>>> imgCT=fredtools.readMHD('CT.mhd', displayInfo=True)
Coordinate transformations
- fredtools.transformIndexToPhysicalPoint(img: Image, indices: Iterable[Iterable[int | float | number]]) Tuple[Tuple[float, ...], ...]
Transform indices to physical points.
The function transforms an iterable of indices into a tuple of physical points based on the frame of reference (FoR) of an image defined as an instance of a SimpleITK image object. The function is a wrapper for TransformIndexToPhysicalPoint SimpleITK function, but it works for multiple points. The shape of indices must be NxD, where N is the number of points to be converted, and D is the dimension of the image.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
indices (NxD array_like) – An iterable (numpy array, list of lists, etc) of N points. Every index must be of the image dimension size and of any integer type (int64, uint16, etc.).
- Returns:
A NxD tuple of tuples with physical points.
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
AttributeError – If indices is not of an integer type or is not of the NxD shape, where D is the image dimension.
See also
transformContinuousIndexToPhysicalPointtransform continuous indices to physical points.
transformPhysicalPointToIndextransform physical points to indices.
transformPhysicalPointToContinuousIndextransform physical points to continuous indices.
- fredtools.transformContinuousIndexToPhysicalPoint(img: Image, indices: Iterable[Iterable[int | float | number]]) Tuple[Tuple[float, ...], ...]
Transform continuous indices to physical points.
The function transforms an iterable of indices into a tuple of physical points based on the frame of reference (FoR) of an image defined as an instance of a SimpleITK image object. The function is a wrapper for TransformContinuousIndexToPhysicalPoint SimpleITK function, but it works for multiple points. The shape of indices must be NxD, where N is the number of points to be converted, and D is the dimension of the image.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
indices (NxD array_like) – An iterable (numpy array, list of lists, etc) of N points. Every index must be of the image dimension size and can be of float or integer type.
- Returns:
A NxD tuple of tuples with physical points.
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
AttributeError – If indices is not of the NxD shape, where D is the image dimension.
See also
transformIndexToPhysicalPointtransform indices to physical points.
transformPhysicalPointToIndextransform physical points to indices.
transformPhysicalPointToContinuousIndextransform physical points to continuous indices.
- fredtools.transformPhysicalPointToIndex(img: Image, points: Iterable[Iterable[int | float | number]]) Tuple[Tuple[int, ...], ...]
Transform physical points to indices.
The function transforms an iterable of points into a tuple of indices based on the frame of reference (FoR) of an image defined as an instance of a SimpleITK image object. The function is a wrapper for TransformPhysicalPointToIndex SimpleITK function, but it works for multiple points. The shape of points must be NxD, where N is the number of points to be converted, and D is the dimension of the image.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
points (NxD array_like) – An iterable (numpy array, list of lists, etc) of N points. Every point must be of the image dimension size.
- Returns:
A NxD tuple of tuples with indices.
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
AttributeError – If points is not of the NxD shape, where D is the image dimension.
See also
transformIndexToPhysicalPointtransform indices to physical points.
transformContinuousIndexToPhysicalPointtransform continuous indices to physical points.
transformPhysicalPointToContinuousIndextransform physical points to continuous indices.
- fredtools.transformPhysicalPointToContinuousIndex(img: Image, points: Iterable[Iterable[int | float | number]]) Tuple[Tuple[float, ...], ...]
Transform physical points to continuous indices.
The function transforms an iterable of points into a tuple of continuous indices based on the frame of reference (FoR) of an image defined as an instance of a SimpleITK image object. The function is a wrapper for TransformPhysicalPointToContinuousIndex SimpleITK function, but it works for multiple points. The shape of points must be NxD, where N is the number of points to be converted, and D is the dimension of the image.
- Parameters:
img (SimpleITK Image) – An object of a SimpleITK image.
points (NxD array_like) – An iterable (numpy array, list of lists, etc) of N points. Every point must be of the image dimension size.
- Returns:
A NxD tuple of tuples with continuous indices.
- Return type:
tuple
- Raises:
TypeError – If img is not an instance of a SimpleITK image.
AttributeError – If points is not of the NxD shape, where D is the image dimension.
See also
transformIndexToPhysicalPointtransform indices to physical points.
transformContinuousIndexToPhysicalPointtransform continuous indices to physical points.
transformPhysicalPointToIndextransform physical points to indices.
Image display
Functions and classes for image displaying. The functionalities have been designed to quickly display and analyse 3D images of CT and/or dose (or any other 3D quantity distribution) in jupyter, including the interactive mode.
- fredtools.showSlice(ax: Axes, imgBack: Image | None = None, imgFront: Image | None = None, plane: str = 'XY', point: Iterable[int | float | number] | None = None, cmapBack: str | Colormap = 'bone', cmapFront: str | Colormap = 'jet', alphaFront: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=0), Le(le=1)])] = 0.7, imgROIs: Iterable[Image] | None = None, vmaxBack: float | None = None, vmaxFront: float | None = None, showLegend: bool = True, fontsize: Annotated[int, Ge(ge=0)] = 8) AxesImage
Display image slice in front of another image slice including contours.
The function displays on ax a plane going through point of a 3D image describing the front image overlapped on a slice of another image describing the background. It forms a simple wrapper to matplotlib.pyplot.imshow allowing for a quick display of a slice from a 3D image of signal (e.g. dose) and/or another image (e.g. CT).
Usually imgBack describes the CT and imgFront describes the dose or other signal. At least one variable, imgBack or imgFront must be given.
- Parameters:
ax (AxesSubplot) – Axis to plot the image on.
imgBack (SimpleITK Image, optional) – Object of a SimpleITK 3D image describing the background image. (def. None)
imgFront (SimpleITK Image, optional) – Object of a SimpleITK 3D image describing the foreground image. (def. None)
plane (str, optional) – Plane to generate the 2D slice given as a string. See fredtools.getSlice for more details. (def. ‘XY’)
point (array_like, optional) – 3D point to generate the 2D slice through. If None then the center of mass of the 3D foreground image (or background image if the foreground image is not given) will be used. (def. None)
cmapBack (string or matplotlib.colors.Colormap, optional) – Colormap to display the background image slice. (def. ‘bone’)
cmapFront (string or matplotlib.colors.Colormap, optional) – Colormap to display the foreground image slice. (def. ‘jet’)
imgROIs (SimpleITK Image or list of SimpleITK Images, optional) – An Instance of a SimpleITK image or list of instances of SimpleITK image objects describing a 3D mask. (def. None)
vmaxBack (scalar, optional) – Maximum value of the background image. If None then the maximum value of the 3D background image will be used. (def. None)
vmaxFront (scalar, optional) – Maximum value of the foreground dose map. If None then the maximum value of the 3D foreground image will be used. (def. None)
alphaFront (float, optional) – Alpha value of the transparency of the foreground image. (def. 0.7)
showLegend (bool, optional) – Show legend of the ROI contour names if they exist. (def. True)
fontsize (scalar, optional) – Basic font size to be used for ticks, labels, legend, etc. (def. 8)
- Returns:
Foreground image (or background image if the foreground image is not given) attached to the axis ax.
- Return type:
matplotlib.image.AxesImage
- Raises:
AttributeError – If neither imgBack nor imgFront is given, or if the image slice cannot be displayed.
ValueError – If cmapBack or cmapFront colormap cannot be recognised.
TypeError – If any of the imgROIs is not an instance of a SimpleITK image describing a binary or floating mask.
See also
showSlicesshow three projections of a 3D image, also interactively.
getSliceget a 2D image slice from SimpleITK Image.
Examples
- class fredtools.showSlices(imgBack: Image | None = None, imgFront: Image | None = None, imgROIs: Iterable[Image] | None = None, point: Iterable[int | float | number] | None = None, DCOFront: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=0), Le(le=1)])] = 0.1, cmapBack: str | Colormap = 'bone', cmapFront: str | Colormap = 'jet', figsize: Iterable[int | float | number] = (15, 5))
Class to display three projections of 3D image slices on an another 3D image slices including contours.
The class creates a figure with three axes and displays three projections (planes), ‘XY’, ‘ZY’ and ‘X-Z’ (reversed Z), going through point, of a 3D image describing foreground overlapped on a background image. The class can display in an interactive mode exploiting ipywidgets functionality, allowing to move slices with a mouse wheel or move slices to the point when the mouse button is pressed. All those interactive features work with Shift pressed.
Usually imgBack describes the CT and imgFront describes the dose or other signal. At least one variable, imgBack or imgFront must be given.
- Parameters:
imgBack (SimpleITK Image, optional) – Object of a 3D SimpleITK image describing the background image. (e.g. CT). (def. None)
imgFront (SimpleITK Image, optional) – Object of a 3D SimpleITK image describing the foreground image. (e.g. dose or gamma index map). (def. None)
imgROIs (SimpleITK Image or list of SimpleITK Images, optional) – An Instance of a SimpleITK image or list of instances of SimpleITK image objects describing a 3D mask. (def. None)
point (array_like, optional) – 3D point to generate the 2D slice through. If None then the center of mass of the 3D foreground image (or the background image if the foreground is not given) will be used. (def. None)
DCOFront (float, optional) – Dose cut-off. The fraction of the maximum value of the foreground image below which the data will not be displayed. (def. 0.1)
cmapBack (string or matplotlib.colors.Colormap, optional) – Colormap to display the background image slice. (def. ‘bone’)
cmapFront (string or matplotlib.colors.Colormap, optional) – Colormap to display the foreground image slice. (def. ‘jet’)
figsize (2-element list, optional) – Width and height of the figure in inches. (def. [15, 5])
- Raises:
AttributeError – If neither imgBack nor imgFront is given.
ValueError – If point is not a 3-element vector, or if cmapBack or cmapFront colormap cannot be recognised.
Notes
1. The foreground image is thresholded destructively on the instance: the imgFront attribute stores a copy of the foreground image in which all values below DCOFront times the image maximum are replaced with NaN (the image object passed by the caller is not modified).
2. The interactive slicing (sliders, mouse wheel and mouse button with Shift pressed) is only activated when the matplotlib backend is ‘widget’ or ‘ipympl’ (i.e. in Jupyter with the ipympl backend). For any other backend, the three static slices going through point are displayed.
Examples
- mouseButtonPressEvent(event)
Move the slices to the clicked point (with Shift pressed) by updating the sliders of the other two axes.
- removeArtist(ax)
Remove all line and collection artists (contours and point lines) as well as the legend from an axis.
- replotPointLines()
Redraw the crosshair lines marking the current point position on all three axes.
- scrollEvent(event)
Move the slice of the axis under the cursor by one voxel per mouse-wheel step (with Shift pressed).
- scrollEventShiftPress(event)
Enable the interactive scroll/click mode when the Shift key is pressed.
- scrollEventShiftRelease(event)
Disable the interactive scroll/click mode when the Shift key is released.
- showSliceAX0(Z)
Replot the first (left) axis with the ‘XY’ plane slice, driven by the Z coordinate.
- showSliceAX1(X)
Replot the second (middle) axis with the ‘ZY’ plane slice, driven by the X coordinate.
- showSliceAX2(Y)
Replot the third (right) axis with the ‘X-Z’ (reversed Z) plane slice, driven by the Y coordinate.
Spot analysis
- fredtools.fitSpotProfile(pos: ArrayLike, vec: ArrayLike, cutLevel: Annotated[float, Ge(ge=0)] | None = None, fixAmplitude: bool = False, fixCenterToZero: bool = False, method: Literal['singleGauss'] = 'singleGauss') fitResult
Fit a gaussian-like function to profile.
The function fits a gaussian-like function defined by method to a profile defined as pos and vec parameters, where they are vectors of positions and values, respectively. The fit is performed with the fit function. For the “singleGauss” method, the fitted model is modelGauss1D without a background, i.e. with the offset fixed to zero.
- Parameters:
pos (array_like 1xN) – An iterable with the positions of the values.
vec (array_like 1xN) – An iterable with the values corresponding to pos.
cutLevel (scalar or None, optional) – Fraction of the maximum value of vec for which the fit will be performed. Only the points with values greater than or equal to max(vec)*`cutLevel` are used in the fit. With 0, the points with negative values are not used. With None, all the points are used, including the negative ones. (def. None)
fixAmplitude (bool, optional) – Fix the amplitude to the maximum value of vec and do not use it in the fitting. (def. False)
fixCenterToZero (bool, optional) – Fix the center to zero and do not use it in the fitting. (def. False)
method ({"singleGauss"}, optional) – Method of the fitting. Only single gaussian fitting is implemented now. (def. “singleGauss”)
- Returns:
An object of the fitResult class with the results of the fit. For the “singleGauss” method, the parameters are ‘amplitude’, ‘center’, ‘sigma’ and ‘offset’, which is fixed to zero.
- Return type:
- Raises:
TypeError – If pos or vec is not iterable, is not a one-dimensional vector, or if pos and vec are not of the same length.
ValueError – If the method is not recognised, if too few points are to be used in the fit (at least 3 points and more points than the fitted parameters are needed), or if the maximum value of the points to be used is not positive.
See also
fitSpotImgfit a 2D gaussian-like function to a spot image.
fitfit a model function to data.
fitResultresult of a fit.
modelGauss1Dmodel of a one-dimensional Gaussian with a constant offset.
guessGauss1Dguess the start values of the parameters of the one-dimensional Gaussian model.
Notes
The start values of the parameters are estimated with guessGauss1D. The amplitude is limited to non-negative values and the sigma to positive values.
The fit result describes all the points of the profile: data, bestFit and residual are arrays of the length of vec, and usedMask tells which points were used in the fit, i.e. which were not below the cut level. The number of the used points is nData.
A cut level selects the points by their own values. When the data are noisy, the points near the cut level whose noise is positive are preferred, and the fitted sigma becomes too large. The effect grows with the noise and with the cut level: for a noise of 2% of the amplitude, the fitted sigma is too large by less than 1% for cutLevel up to 0.5 and by a few percent for cutLevel of 0.8. With cutLevel=None, all the points are used and the effect does not occur.
Examples
Fit a Gaussian to the points of a profile with the values of at least 20% of the maximum and get the fitted parameters, the uncertainty of the fitted sigma and the full width at half maximum with its uncertainty.
>>> result = fredtools.fitSpotProfile(pos, vec, cutLevel=0.2) >>> result.bestValues {'amplitude': 7.092330861945428, 'center': 1.5184938240621777, 'sigma': 2.499049220377759, 'offset': 0.0} >>> result.params["sigma"].stderr 0.021387031047437343 >>> result.derive(lambda sigma: fredtools.sigma2fwhm(sigma)) (5.884811197664513, 0.050362609195072364)
- fredtools.fitSpotImg(img: Image, cutLevel: Annotated[float, Ge(ge=0)] | None = None, fixAmplitude: bool = False, fixCenterToZero: bool = False, method: Literal['singleGauss'] = 'singleGauss') fitResult
Fit a 2D gaussian-like function to spot image.
The function fits a 2D gaussian-like function defined by method to a spot image defined as img parameter, which is a 2D SimpleITK image. The fit is performed with the fit function at the physical positions of the voxel centers. For the “singleGauss” method, the fitted model is modelGauss2D without a background, i.e. with the offset fixed to zero.
- Parameters:
img (SITKImage) – 2D SimpleITK image of the spot.
cutLevel (scalar or None, optional) – Fraction of the maximum value of img for which the fit will be performed. Only the voxels with values greater than or equal to max(img)*`cutLevel` are used in the fit. With 0, the voxels with negative values are not used. With None, all the voxels are used, including the negative ones. (def. None)
fixAmplitude (bool, optional) – Fix the amplitude to the maximum value of img and do not use it in the fitting. (def. False)
fixCenterToZero (bool, optional) – Fix the center to zero and do not use it in the fitting. (def. False)
method ({"singleGauss"}, optional) – Method of the fitting. Only single gaussian fitting is implemented now. (def. “singleGauss”)
- Returns:
An object of the fitResult class with the results of the fit. For the “singleGauss” method, the parameters are ‘amplitude’, ‘centerX’, ‘centerY’, ‘sigmaX’, ‘sigmaY’, ‘rotation’ (in degrees) and ‘offset’, which is fixed to zero.
- Return type:
- Raises:
TypeError – If img is not a 2D SimpleITK image of a scalar pixel type.
ValueError – If the method is not recognised, if too few voxels are to be used in the fit (at least 6 voxels and more voxels than the fitted parameters are needed), or if the maximum value of the voxels to be used is not positive.
See also
fitSpotProfilefit a gaussian-like function to a profile.
findSpotsfind spots in a 2D image.
fitfit a model function to data.
fitResultresult of a fit.
modelGauss2Dmodel of a two-dimensional rotated Gaussian with a constant offset.
guessGauss2Dguess the start values of the parameters of the two-dimensional Gaussian model.
Notes
The start values of the parameters are estimated with guessGauss2D. The amplitude is limited to non-negative values and the sigmas to positive values. The fit starts with the rotation in the range from -45 to 45 degrees, i.e. with sigmaX as the width along the axis of the spot which is closer to the X axis, and the fitted rotation is not limited. The same spot is described by the rotation changed by 180 degrees, and by the rotation changed by 90 degrees with sigmaX and sigmaY swapped (see modelGauss2D). For a round spot (sigmaX equal to sigmaY), the rotation cannot be determined: its fitted value is arbitrary and its uncertainty is large, and the other parameters are not affected.
The fit result describes all the voxels of the image: data, bestFit, residual and usedMask are images with the frame of reference of img, and usedMask tells which voxels were used in the fit, i.e. which were not below the cut level. The number of the used voxels is nData.
A cut level selects the voxels by their own values. When the image is noisy, the voxels near the cut level whose noise is positive are preferred, and the fitted sigmas become too large. The effect grows with the noise and with the cut level: for a noise of 2% of the amplitude, the fitted sigmas are too large by less than 1% for cutLevel up to 0.5 and by a few percent for cutLevel of 0.8. With cutLevel=None, all the voxels are used and the effect does not occur.
Examples
Fit a Gaussian to the voxels of a spot image with the values of at least 10% of the maximum and get the fitted parameters and the uncertainty of the fitted sigmaX.
>>> result = fredtools.fitSpotImg(img, cutLevel=0.1) >>> result.bestValues {'amplitude': 9.967678658241248, 'centerX': 1.9929492906918742, 'centerY': -2.992105775410638, 'sigmaX': 3.012686292869613, 'sigmaY': 5.03013765044176, 'rotation': 29.72428292358477, 'offset': 0.0} >>> result.params["sigmaX"].stderr 0.0070061660384697
Get the fitted spot as an image and display the summary of the fit.
>>> imgFit = result.bestFit >>> print(result.report())
- fredtools.findSpots(img: Image, DCO: Annotated[int | float | number, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=0), Le(le=1)])] = 0.1, margin: Annotated[float, Ge(ge=0)] | Iterable[Annotated[float, Ge(ge=0)]] = 3, displayInfo: bool = False) Image
Find spots in 2D SITK image.
The function identifies spots in a 2D SimpleITK image by applying a dose cut-off (DCO) to define the spot region, followed by morphological operations to refine the regions. The identified spots are then labelled and returned as a labelled image. In detail, the image is first smoothed with a median filter of a fixed 5x5 voxel kernel and binarised at DCO times the image maximum. The binary regions are dilated by margin (converted from mm to voxels), labelled as fully connected components with holes filled, and components smaller than 20 voxels are dropped. The remaining labels are sorted by size (the largest component gets label 1), and finally each label region is replaced by its axis-aligned bounding box, so each spot is described by a rectangular label region. If the image has no positive values (its maximum is not positive), no spots can be identified: a warning is logged and an empty label image is returned.
- Parameters:
img (SITKImage) – 2D SITK image.
DCO (Numeric, optional) – Dose cut-off to define spot region. (def. 0.1)
margin (Numeric | Iterable[Numeric], optional) – Non-negative margin around spot region in mm, given as a single value for all directions or as an iterable with one value per image dimension. (def. 3)
displayInfo (bool, optional) – Display information about found spots. (def. False)
- Returns:
Labelled image of found spots, of ‘8-bit unsigned integer’ type and in the frame of reference of img. The voxels outside the spots are 0, so the image is filled with zeros if no spot was found.
- Return type:
SITKImage
- Raises:
TypeError – If img is not a 2D SimpleITK image. If margin is not a scalar or an iterable of scalars with one value per image dimension.
ValueError – If DCO is not a positive scalar between 0 and 1. If any value of margin is negative.
- fredtools.fitSigmaSquaredModel(pos: Iterable[int | float | number], beamSize: Iterable[int | float | number]) fitResult
Fit sigma squared model to beam size data.
The function fits the sigma squared model to the beam size data provided. The model is defined as: σ²(z) = a + b*z + c*z², where σ is the beam size at position z, and a, b, c are the parameters to be fitted. Note that the fit is performed on the squared beam size, i.e.
beamSize**2. The fit is performed with the fit function.- Parameters:
pos (Iterable[Numeric]) – Positions where the beam sizes were measured.
beamSize (Iterable[Numeric]) – Measured beam sizes at the corresponding positions.
- Returns:
An object of the fitResult class with the results of the fit. The parameters are ‘a’, ‘b’ and ‘c’, and the parameter ‘c’ is limited to non-negative values. The data and bestFit of the result are the squared beam sizes.
- Return type:
- Raises:
TypeError – If pos or beamSize is not iterable, is not a one-dimensional vector, or if pos and beamSize are not of the same length.
ValueError – If fewer than 4 points are given, because the fit needs more points than the fitted parameters.
Examples
Fit the model to the beam sizes measured at several positions and calculate the fitted beam size at a given position.
>>> result = fredtools.fitSigmaSquaredModel(pos, beamSize) >>> result.bestValues {'a': 9.10313763996811, 'b': 0.004040803834976309, 'c': 0.0001968416450660723} >>> float(numpy.sqrt(result.eval(50.0))) 3.13006101288491
DVH analysis
Functions for Dose-Volume Histogram (DVH) analysis. The DVH data is returned as an instance of the DVH class described below.
- fredtools.getDVHMask(img: Image, imgMask: Image, dosePrescribed: Annotated[float, Ge(ge=0)], displayInfo: bool = False) DVH
Calculate DVH for the mask.
The function calculates a dose-volume histogram (DVH) for voxels inside a mask with the same field of reference (FoR). The mask must be defined as a SimpleITK image object describing a binary or floating mask. The routine exploits and returns DVH class to hold the DVH. The class has been adapted from dicompyler-core DVH module (https://dicompyler-core.readthedocs.io/en/latest/index.html)
- Parameters:
img (SimpleITK Image) – Object of a SimpleITK 3D image.
imgMask (SimpleITK Image) – Object of a SimpleITK 3D image describing the binary or floating mask.
dosePrescribed (scalar) – Target prescription dose.
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
An instance of a DVH class holding the DVH.
- Return type:
- Raises:
TypeError – If img or imgMask is not an instance of a 3D SimpleITK image, if imgMask does not describe a binary or floating mask, or if img and imgMask do not have the same FoR.
ValueError – If the image contains NaN values inside the mask.
See also
resampleImgresample image.
mapStructToImgmap structure to image (refer for more information about mapping algorithms).
getDVHStructcalculate DVH for structure.
- fredtools.getDVHStruct(img: Image, RSfileName: str, structName: str, dosePrescribed: float, resampleImg: float | Iterable[float] | None = None, displayInfo: bool = False) DVH
Calculate DVH for the structure.
The function calculates a dose-volume histogram (DVH) for voxels inside a structure named structName and is defined in the structure dicom file. The image can be resampled before mapping to increase the resolution. The routine exploits and returns DVH class to hold the DVH. The class has been adapted from dicompyler-core DVH module (https://dicompyler-core.readthedocs.io/en/latest/index.html)
- Parameters:
img (SimpleITK Image) – Object of a SimpleITK 3D image.
RSfileName (path) – String path to RS dicom file.
structName (string) – Name of the structure to calculate the DVH in.
dosePrescribed (scalar) – Target prescription dose.
resampleImg (scalar, array_like or None, optional) – Define if and how to resample the image while mapping the structure. Can be a scalar, then the same number will be used for each axis, 3-element iterable defining the voxel size for each axis, or None meaning no interpolation. (def. None)
displayInfo (bool, optional) – Displays a summary of the function results. (def. False)
- Returns:
An instance of a DVH class holding the DVH.
- Return type:
- Raises:
TypeError – If img is not an instance of a 3D SimpleITK image, or if RSfileName is not a proper dicom file describing structures.
AttributeError – If the structure structName cannot be found in the RSfileName dicom file.
ValueError – If the shape of resampleImg does not match the image dimension and is not a scalar.
See also
resampleImgresample image.
mapStructToImgmap structure to image (refer for more information about mapping algorithms).
getDVHMaskcalculate DVH for a mask.
Notes
The structure mapping is performed in ‘floating’ mode meaning that the fractional structure occupancy is assigned to each voxel of the image. Use getDVHMask to use a specially prepared mask for the DVH calculation.
- class fredtools.ImgAnalyse.dvhAnalyse.DVH(volume: Iterable[int | float | number], dose: Iterable[int | float | number], type: Literal['cumulative', 'differential'] = 'cumulative', dosePrescribed: int | float | number | None = None, name: str | None = None, color: str | Sequence[int | float | number] | None = None)
Class that stores dose volume histogram (DVH) data.
- compare(other: Self) None
Compare two DVHs.
The method compares two DVHs in terms of basic DVH parameters and plots the DVHs.
- Parameters:
other (DVH) – DVH instance to compare against.
- Raises:
TypeError – If the comparison object is not a DVH instance.
- displayInfo() None
Describe a summary of DVH statistics in a text based format.
- doseConstraint(volume: int | float | number, absolute: bool = False) float
Calculate dose constraint for a specific volume.
The method calculates the maximum dose that a specific absolute or relative volume receives. e.g.: D90, D100, D2cc , etc. The results is always given in the absolute dose units.
- Parameters:
volume (Numeric) – Volume used to determine the maximum dose that the volume receives. Can either be in relative or absolute volume units.
absolute (bool, optional) – If True, the volume is considered in absolute units. (def. False)
- Returns:
Absolute dose that a specific volume receives.
- Return type:
number
- Raises:
AttributeError – If the volume value is negative.
- property doseDiffCenters: NDArray
Return a numpy array containing the dose bin centers for differential type.
- property doseDiffEdges: NDArray
Return a numpy array containing the bin edges for differential type.
- property doseLevels: NDArray
Return a numpy array containing the dose levels for cumulative type.
- property dosePrescribed: float
Return the prescribed dose.
- property max: float
Return the maximum dose.
- property mean: float
Return the mean dose.
- property median: float
Return the median dose.
- property min: float
Return the minimum dose.
- plot() None
Plot the DVH using Matplotlib if present.
- statistic(name: str) float
DVH dose or volume statistics
The method returns DVH dose or volume statistics. The statistics can be in the form of D90, D100, D2cc, V100, V20Gy, etc.
- Parameters:
name (str) – DVH statistic in the form of D90, D100, D2cc, V100, V20Gy, etc.
- Returns:
Value from the dose or volume statistic calculation.
- Return type:
Numeric
- Raises:
AttributeError – If the attribute name cannot be resolved.
- property stdDev: float
Return the standard deviation of the dose.
- property volume: float
Return the volume of the structure.
- volumeConstraint(dose: int | float | number, absolute: bool = False) float
Calculate volume constraint for a specific dose.
The method calculates the volume that receives at least a specific relative or absolute dose. e.g.: V100, V50, V20Gy, etc.
- Parameters:
dose (Numeric) – Dose value used to determine minimum volume that receives this dose. Can either be in relative or absolute dose units.
absolute (bool, optional) – If True, the dose is considered in absolute units. (def. False)
- Returns:
Volume that receives at least a specific dose.
- Return type:
Numeric
- Raises:
AttributeError – If the dose value is negative.
- property volumeCumAbs: NDArray
Return a numpy array containing the absolute cumulative volume for each dose level.
- property volumeCumRel: NDArray
Return a numpy array containing the relative cumulative volume for each dose level.
- property volumeDiffAbs: NDArray
Return a numpy array containing the absolute differential volume for each bin.
- property volumeDiffRel: NDArray
Return a numpy array containing the relative differential volume for each bin.