CatPhan module documentation

Overview

The CatPhan module automatically analyzes DICOM images of a CatPhan 504, 503, or 600 acquired when doing CBCT or CT quality assurance. It can load a folder or zip file that the images are in and automatically correct for translational and rotational errors. It can analyze the HU regions and image scaling (CTP404), the high-contrast line pairs (CTP528) to calculate the modulation transfer function (MTF), the HU uniformity (CTP486), and Low Contrast (CTP515) on the corresponding slices.

Features:

  • Automatic phantom registration - Your phantom can be tilted, rotated, or translated–pylinac will automatically register the phantom.
  • Automatic testing of all major modules - Major modules are automatically registered and analyzed.
  • Any scan protocol - Scan your CatPhan with any protocol; even scan it in a regular CT scanner. Any field size or field extent is allowed.

Running the Demo

To run one of the CatPhan demos, create a script or start an interpreter and input:

from pylinac import CatPhan504
CatPhan504.run_demo() # the demo is a Varian high quality head scan

Results will be printed to the console and a figure showing the slices analyzed will pop up:

 - CatPhan 504 QA Test -
HU Linearity ROIs: {'Poly': -45.0, 'PMP': -200.0, 'Acrylic': 115.0, 'Teflon': 997.0, 'Delrin': 340.0, 'Air': -998.0, 'LDPE': -102.0}
HU Passed?: True
Uniformity ROIs: {'Center': 14.0, 'Top': 6.0, 'Left': 10.0, 'Bottom': 5.0, 'Right': 0.0}
Uniformity index: -1.3806706114398422
Integral non-uniformity: 0.006951340615690168
Uniformity Passed?: True
MTF 50% (lp/mm): 0.95
Low contrast ROIs "seen": 3
Low contrast visibility: 3.4654015681608437
Geometric Line Average (mm): 49.93054775087732
Geometry Passed?: True
Slice Thickness (mm): 2.5007568359375
Slice Thickness Passed? True

(Source code, png, hires.png, pdf)

_images/cbct_docs-1.png

As well, you can plot and save individual pieces of the analysis:

cbct = CatPhan504.from_demo_images()
cbct.analyze()
cbct.plot_analyzed_subimage('linearity')
cbct.save_analyzed_subimage('linearity.png', subimage='linearity')

Or:

cbct.plot_analyzed_subimage('rmtf')

Or generate a PDF report:

cbct.publish_pdf('mycbct.pdf')

Typical Use

CatPhan analysis as done by this module closely follows what is specified in the CatPhan manuals, replacing the need for manual measurements. There are 4 CatPhan models that pylinac can analyze: CatPhan504, CatPhan503, & CatPhan600, & CatPhan604, each with their own class in pylinac. Let’s assume you have the CatPhan504 for this example. Using the other models/classes is exactly the same except the class name.

from pylinac import CatPhan504  # or import the CatPhan503 or CatPhan600

The minimum needed to get going is to:

  • Load images – Loading the DICOM images into your CatPhan object is done by passing the images in during construction. The most direct way is to pass in the directory where the images are:

    cbct_folder = r"C:/QA Folder/CBCT/June monthly"
    mycbct = CatPhan504(cbct_folder)
    

    or load a zip file of the images:

    zip_file = r"C:/QA Folder/CBCT/June monthly.zip"
    mycbct = CatPhan504.from_zip(zip_file)
    

    You can also use the demo images provided:

    mycbct = CatPhan504.from_demo_images()
    
  • Analyze the images – Once the folder/images are loaded, tell pylinac to start analyzing the images. See the Algorithm section for details and analyze`() for analysis options:

    mycbct.analyze()
    
  • View the results – The CatPhan module can print out the summary of results to the console as well as draw a matplotlib image to show where the samples were taken and their values:

    # print results to the console
    print(mycbct.return_results())
    # view analyzed images
    mycbct.plot_analyzed_image()
    # save the image
    mycbct.save_analyzed_image('mycatphan504.png')
    # generate PDF
    mycbct.publish_pdf('mycatphan.pdf', open_file=True)  # open the PDF after saving as well.
    

Algorithm

The CatPhan module is based on the tests and values given in the respective CatPhan manual. The algorithm works like such:

Allowances

  • The images can be any size.
  • The phantom can have significant translation in all 3 directions.
  • The phantom can have significant roll and moderate yaw and pitch.

Restrictions

Warning

Analysis can fail or give unreliable results if any Restriction is violated.

  • The phantom used must be an unmodified CatPhan 504, 503, or 600.
  • All of the relevant modules must be within the scan extent; i.e. one can’t scan only part of the phantom.

Pre-Analysis

  • Determine image properties – Upon load, the image set is analyzed for its DICOM properties to determine mm/pixel spacing, rescale intercept and slope, manufacturer, etc.

  • Convert to HU – The entire image set is converted from its raw values to HU by applying the rescale intercept and slope which is contained in the DICOM properties.

  • Find the phantom z-location – Upon loading, all the images are scanned to determine where the HU linearity module (CTP404) is located. This is accomplished by examining each image slice and looking for 2 things:

    • If the CatPhan is in the image. At the edges of the scan this may not be true.
    • If a circular profile has characteristics like the CTP404 module. If the CatPhan is in the image, a circular profile is taken at the location where the HU linearity regions of interest are located. If the profile contains low, high, and lots of medium values then it is very likely the HU linearity module. All such slices are found and the median slice is set as the HU linearity module location. All other modules are located relative to this position.

Analysis

  • Determine phantom roll – Precise knowledge of the ROIs to analyze is important, and small changes in rotation could invalidate automatic results. The roll of the phantom is determined by examining the HU module and converting to a binary image. The air holes are then located and the angle of the two holes determines the phantom roll.

    Note

    For each step below, the “module” analyzed is actually the mean, median, or maximum of 3 slices (+/-1 slice around and including the nominal slice) to ensure robust measurements. Also, for each step/phantom module, the phantom center is determined, which corrects for the phantom pitch and yaw.

    Additionally, values tend to be lazy (computed only when asked for), thus the calculations listed may sometimes be performed only when asked for.

  • Determine HU linearity – The HU module (CTP404) contains several materials with different HU values. Using hardcoded angles (corrected for roll) and radius from the center of the phantom, circular ROIs are sampled which correspond to the HU material regions. The mean pixel value of the ROI is the stated HU value.

  • Determine HU uniformity – HU uniformity (CTP486) is calculated in a similar manner to HU linearity, but within the CTP486 module/slice.

  • Calculate Geometry/Scaling – The HU module (CTP404), besides HU materials, also contains several “nodes” which have an accurate spacing (50 mm apart). Again, using hardcoded but corrected angles, the area around the 4 nodes are sampled and then a threshold is applied which identifies the node within the ROI sample. The center of mass of the node is determined and then the space between nodes is calculated.

  • Calculate Spatial Resolution/MTF – The Spatial Resolution module (CTP528) contains 21 pairs of aluminum bars having varying thickness, which also corresponds to the thickness between the bars. One unique advantage of these bars is that they are all focused on and equally distant to the phantom center. This is taken advantage of by extracting a CollapsedCircleProfile about the line pairs. The peaks and valleys of the profile are located; peaks and valleys of each line pair are used to calculated the MTF. The relative MTF (i.e. normalized to the first line pair) is then calculated from these values.

  • Calculate Low Contrast Resolution – Low contrast is inherently difficult to determine since detectability of humans is not simply contrast based. Pylinac’s analysis uses both the contrast value of the ROI as well as the ROI size to compute a “detectability” score. ROIs above the score are said to be “seen”, while those below are not seen. Only the 1.0% supra-slice ROIs are examined. Two background ROIs are sampled on either side of the ROI contrast set. The score for a given ROI is calculated like so \(\frac{ROI_{pixel} - background}{ROI_{stdev}} * ROI_{diameter}\), where \(ROI_{pixel}\) is the mean pixel value of the ROI, \(background\) is the mean pixel value of the two background ROIs, and \(ROI_{diameter}\) is the diamter of the ROI in mm. The default detectability score is 10.

  • Calculate Slice Thickness – Slice thickness is measured by determining the FWHM of the wire ramps in the CTP404 module. A profile of the area around each wire ramp is taken, and the FWHM is determined from the profile. Based on testing, the FWHM is not always perfectly detected and may not “catch” the profile, giving an undervalued representation. Thus, the two longest profiles are averaged and the value is converted from pixels to mm and multiplied by 0.42.

Post-Analysis

  • Test if values are within tolerance – For each module, the determined values are compared with the nominal values. If the difference between the two is below the specified tolerance then the module passes.

Troubleshooting

First, check the general Troubleshooting section. Most problems in this module revolve around getting the data loaded.

  • If you’re having trouble getting your dataset in, make sure you’re loading the whole dataset. Also make sure you’ve scanned the whole phantom.
  • Make sure there are no external markers on the CatPhan (e.g. BBs), otherwise the localization algorithm will not be able to properly locate the phantom within the image.
  • Ensure that the FOV is large enough to encompass the entire phantom. If the scan is cutting off the phantom in any way it will not identify it.
  • The phantom should never touch the edge of an image, see above point.
  • Make sure you’re loading the right CatPhan class. I.e. using a CatPhan600 class on a CatPhan504 scan may result in errors or erroneous results.

API Documentation

The CatPhan classes uses several other classes. There are several Slices of Interest (SOI), most of which contain Regions of Interest (ROI).

class pylinac.ct.CatPhan504(folderpath, check_uid=True)[source]

Bases: pylinac.ct.CatPhanBase

A class for loading and analyzing CT DICOM files of a CatPhan 504. Can be from a CBCT or CT scanner Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528), Image Scaling & HU Linearity (CTP404), and Low contrast (CTP515).

Parameters:
  • folderpath (str) – String that points to the CBCT image folder location.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
Raises:
  • NotADirectoryError : If folder str passed is not a valid directory.
  • FileNotFoundError : If no CT images are found in the folder
static run_demo(show=True)[source]

Run the CBCT demo using high-quality head protocol images.

class pylinac.ct.CatPhan503(folderpath, check_uid=True)[source]

Bases: pylinac.ct.CatPhanBase

A class for loading and analyzing CT DICOM files of a CatPhan 503. Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528), Image Scaling & HU Linearity (CTP404).

Parameters:
  • folderpath (str) – String that points to the CBCT image folder location.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
Raises:
  • NotADirectoryError : If folder str passed is not a valid directory.
  • FileNotFoundError : If no CT images are found in the folder
static run_demo(show=True)[source]

Run the CBCT demo using high-quality head protocol images.

class pylinac.ct.CatPhan600(folderpath, check_uid=True)[source]

Bases: pylinac.ct.CatPhanBase

A class for loading and analyzing CT DICOM files of a CatPhan 600. Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528), Image Scaling & HU Linearity (CTP404), and Low contrast (CTP515).

Parameters:
  • folderpath (str) – String that points to the CBCT image folder location.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
Raises:
  • NotADirectoryError : If folder str passed is not a valid directory.
  • FileNotFoundError : If no CT images are found in the folder
static run_demo(show=True)[source]

Run the CatPhan 600 demo.

class pylinac.ct.CatPhan604(folderpath, check_uid=True)[source]

Bases: pylinac.ct.CatPhanBase

A class for loading and analyzing CT DICOM files of a CatPhan 604. Can be from a CBCT or CT scanner Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528), Image Scaling & HU Linearity (CTP404), and Low contrast (CTP515).

Parameters:
  • folderpath (str) – String that points to the CBCT image folder location.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
Raises:
  • NotADirectoryError : If folder str passed is not a valid directory.
  • FileNotFoundError : If no CT images are found in the folder
static run_demo(show=True)[source]

Run the CBCT demo using high-quality head protocol images.

class pylinac.ct.CatPhanBase(folderpath, check_uid=True)[source]

Bases: object

A class for loading and analyzing CT DICOM files of a CatPhan 504 & CatPhan 503. Can be from a CBCT or CT scanner Analyzes: Uniformity (CTP486), High-Contrast Spatial Resolution (CTP528), Image Scaling & HU Linearity (CTP404).

Parameters:
  • folderpath (str) – String that points to the CBCT image folder location.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
Raises:
  • NotADirectoryError : If folder str passed is not a valid directory.
  • FileNotFoundError : If no CT images are found in the folder
classmethod from_demo_images()[source]

Construct a CBCT object from the demo images.

classmethod from_url(url, check_uid=True)[source]

Instantiate a CBCT object from a URL pointing to a .zip object.

Parameters:
  • url (str) – URL pointing to a zip archive of CBCT images.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
classmethod from_zip(zip_file, check_uid=True)[source]

Construct a CBCT object and pass the zip file.

Parameters:
  • zip_file (str, ZipFile) – Path to the zip file or a ZipFile object.
  • check_uid (bool) – Whether to enforce raising an error if more than one UID is found in the dataset.
Raises:
  • FileExistsError : If zip_file passed was not a legitimate zip file.
  • FileNotFoundError : If no CT images are found in the folder
plot_analyzed_image(show=True)[source]

Plot the images used in the calculate and summary data.

Parameters:show (bool) – Whether to plot the image or not.
save_analyzed_image(filename, **kwargs)[source]

Save the analyzed summary plot.

Parameters:
  • filename (str, file object) – The name of the file to save the image to.
  • kwargs – Any valid matplotlib kwargs.
plot_analyzed_subimage(subimage='hu', delta=True, show=True)[source]

Plot a specific component of the CBCT analysis.

Parameters:
  • subimage ({'hu', 'un', 'sp', 'lc', 'mtf', 'lin', 'prof'}) –

    The subcomponent to plot. Values must contain one of the following letter combinations. E.g. linearity, linear, and lin will all draw the HU linearity values.

    • hu draws the HU linearity image.
    • un draws the HU uniformity image.
    • sp draws the Spatial Resolution image.
    • mtf draws the RMTF plot.
    • lin draws the HU linearity values. Used with delta.
    • prof draws the HU uniformity profiles.
  • delta (bool) – Only for use with lin. Whether to plot the HU delta or actual values.
  • show (bool) – Whether to actually show the plot.
save_analyzed_subimage(filename, subimage='hu', **kwargs)[source]

Save a component image to file.

Parameters:
  • filename (str, file object) – The file to write the image to.
  • subimage (str) – See plot_analyzed_subimage() for parameter info.
localize()[source]

Find the slice number of the catphan’s HU linearity module and roll angle

mm_per_pixel

The millimeters per pixel of the DICOM images.

find_origin_slice[source]

Using a brute force search of the images, find the median HU linearity slice.

This method walks through all the images and takes a collapsed circle profile where the HU linearity ROIs are. If the profile contains both low (<800) and high (>800) HU values and most values are the same (i.e. it’s not an artifact), then it can be assumed it is an HU linearity slice. The median of all applicable slices is the center of the HU slice.

Returns:The middle slice of the HU linearity module.
Return type:int
find_phantom_roll[source]

Determine the “roll” of the phantom.

This algorithm uses the two air bubbles in the HU slice and the resulting angle between them.

Returns:float
Return type:the angle of the phantom in degrees.
num_images

Return the number of images loaded.

Returns:
Return type:float
catphan_size

The expected size of the phantom in pixels, based on a 20cm wide phantom.

Returns:
Return type:float
publish_pdf(filename, author=None, unit=None, notes=None, open=False)[source]

Publish (print) a PDF containing the analysis and quantitative results.

Parameters:filename ((str, file-like object}) – The file to write the results to.
analyze(hu_tolerance=40, scaling_tolerance=1, thickness_tolerance=0.2, low_contrast_tolerance=1, cnr_threshold=15, zip_after=False)[source]

Single-method full analysis of CBCT DICOM files.

Parameters:
  • hu_tolerance (int) – The HU tolerance value for both HU uniformity and linearity.
  • scaling_tolerance (float, int) – The scaling tolerance in mm of the geometric nodes on the HU linearity slice (CTP404 module).
  • thickness_tolerance (float, int) –

    The tolerance of the thickness calculation in mm, based on the wire ramps in the CTP404 module.

    Warning

    Thickness accuracy degrades with image noise; i.e. low mAs images are less accurate.

  • low_contrast_tolerance (int) – The number of low-contrast bubbles needed to be “seen” to pass.
  • cnr_threshold (float, int) – The threshold for “detecting” low-contrast image. See RTD for calculation info.
  • zip_after (bool) – If the CT images were not compressed before analysis and this is set to true, pylinac will compress the analyzed images into a ZIP archive.
results()[source]

Return the results of the analysis as a string. Use with print().

Module classes (CTP404, etc)

class pylinac.ct.Slice(catphan, slice_num=None, combine=True, combine_method='mean', num_slices=0)[source]

Bases: object

Base class for analyzing specific slices of a CBCT dicom set.

Parameters:
  • catphan (~pylinac.cbct.CatPhanBase instance.) –
  • slice_num (int) – The slice number of the DICOM array desired. If None, will use the slice_num property of subclass.
  • combine (bool) – If True, combines the slices +/- num_slices around the slice of interest to improve signal/noise.
  • combine_method ({'mean', 'max'}) – How to combine the slices if combine is True.
  • num_slices (int) – The number of slices on either side of the nominal slice to combine to improve signal/noise; only applicable if combine is True.
phan_center

Determine the location of the center of the phantom.

The image is analyzed to see if: 1) the CatPhan is even in the image (if there were any ROIs detected) 2) an ROI is within the size criteria of the catphan 3) the ROI area that is filled compared to the bounding box area is close to that of a circle

Raises:ValueError – If any of the above conditions are not met.
class pylinac.ct.CatPhanModule(catphan, tolerance, offset=0)[source]

Bases: pylinac.ct.Slice, pylinac.ct.ROIManagerMixin

Base class for a CTP module.

Parameters:
  • catphan (~pylinac.cbct.CatPhanBase instance.) –
  • tolerance (float) –
  • offset (int, float) –
preprocess(catphan)[source]

A preprocessing step before analyzing the CTP module.

Parameters:catphan (~pylinac.cbct.CatPhanBase instance.) –
slice_num

The slice number of the spatial resolution module.

Returns:
Return type:float
class pylinac.ct.CTP404(catphan, offset, hu_tolerance, thickness_tolerance, scaling_tolerance)[source]

Bases: pylinac.ct.CatPhanModule

Class for analysis of the HU linearity, geometry, and slice thickness regions of the CTP404.

Parameters:
  • catphan (~pylinac.cbct.CatPhanBase instance.) –
  • offset (float) –
  • hu_tolerance (float) –
  • thickness_tolerance (float) –
  • scaling_tolerance (float) –
preprocess(catphan)[source]

A preprocessing step before analyzing the CTP module.

Parameters:catphan (~pylinac.cbct.CatPhanBase instance.) –
lcv

The low-contrast visibility

plot_linearity(axis=None, plot_delta=True)[source]

Plot the HU linearity values to an axis.

Parameters:
  • axis (None, matplotlib.Axes) – The axis to plot the values on. If None, will create a new figure.
  • plot_delta (bool) – Whether to plot the actual measured HU values (False), or the difference from nominal (True).
passed_hu

Boolean specifying whether all the ROIs passed within tolerance.

plot_rois(axis)[source]

Plot the ROIs onto the image, as well as the background ROIs

passed_thickness

Whether the slice thickness was within tolerance from nominal.

meas_slice_thickness

The average slice thickness for the 4 wire measurements in mm.

passed_geometry

Returns whether all the line lengths were within tolerance.

class pylinac.ct.CTP528(catphan, tolerance, offset=0)[source]

Bases: pylinac.ct.CatPhanModule

Class for analysis of the Spatial Resolution slice of the CBCT dicom data set.

A collapsed circle profile is taken of the line-pair region. This profile is search for peaks and valleys. The MTF is calculated from those peaks & valleys.

radius2linepairs_mm

The radius in mm to the line pairs.

Type:float
Parameters:
  • catphan (~pylinac.cbct.CatPhanBase instance.) –
  • tolerance (float) –
  • offset (int, float) –
sr_rois

Spatial resolution ROI characteristics.

Returns:
Return type:dict
lp_freq

Line pair frequencies in line pair/mm.

Returns:
Return type:list
mtfs

The Relative MTF of the line pairs, normalized to the first region.

Returns:
Return type:dict
radius2linepairs

Radius from the phantom center to the line-pair region, corrected for pixel spacing.

plot_rois(axis)[source]

Plot the circles where the profile was taken within.

preprocess(catphan)[source]

A preprocessing step before analyzing the CTP module.

Parameters:catphan (~pylinac.cbct.CatPhanBase instance.) –
circle_profile

Calculate the median profile of the Line Pair region.

Returns::class:`pylinac.core.profile.CollapsedCircleProfile`
Return type:A 1D profile of the Line Pair region.
mtf(percent=None, region=None)[source]

Return the MTF value of the spatial resolution. Only one of the two parameters may be used.

Parameters:
  • percent (int, float) – The percent relative MTF; i.e. 0-100.
  • region (int) – The line-pair region desired (1-6).
Returns:

float

Return type:

the line-pair resolution at the given MTF percent or region.

plot_mtf(axis=None)[source]

Plot the Relative MTF.

Parameters:axis (None, matplotlib.Axes) – The axis to plot the MTF on. If None, will create a new figure.
class pylinac.ct.CTP515(catphan, tolerance, cnr_threshold, offset=0)[source]

Bases: pylinac.ct.CatPhanModule

Class for analysis of the low contrast slice of the CTP module. Low contrast is measured by obtaining the average pixel value of the contrast ROIs and comparing that value to the average background value. To obtain a more “human” detection level, the contrast (which is largely the same across different-sized ROIs) is multiplied by the diameter. This value is compared to the contrast threshold to decide if it can be “seen”.

bg_roi_radius

A list of the ROI radii, scaled to pixels.

roi_radius

A list of the ROI radii, scaled to pixels.

rois_visible

The number of ROIs “visible”.

plot_rois(axis)[source]

Plot the ROIs to an axis.

overall_passed

Whether there were enough low contrast ROIs “seen”.

plot_contrast(axis=None)[source]

Plot the contrast constant. :param axis: The axis to plot the contrast on. If None, will create a new figure. :type axis: None, matplotlib.Axes

class pylinac.ct.CTP486(catphan, tolerance, offset=0)[source]

Bases: pylinac.ct.CatPhanModule

Class for analysis of the Uniformity slice of the CTP module. Measures 5 ROIs around the slice that should all be close to the same value.

Parameters:
  • catphan (~pylinac.cbct.CatPhanBase instance.) –
  • tolerance (float) –
  • offset (int, float) –
plot_profiles(axis=None)[source]

Plot the horizontal and vertical profiles of the Uniformity slice.

Parameters:axis (None, matplotlib.Axes) – The axis to plot on; if None, will create a new figure.
overall_passed

Boolean specifying whether all the ROIs passed within tolerance.

uniformity_index

The Uniformity Index

integral_non_uniformity

The Integral Non-Uniformity

ROI Objects

class pylinac.ct.ROIManagerMixin[source]

Bases: object

Class for handling multiple ROIs. Used for the HU linearity, Uniformity, Geometry, Low-contrast, and Thickness slices.

dist2rois_mm

The distance from the phantom center to the ROIs, in mm.

Type:int, float
roi_radius_mm

The radius of the ROIs, in mm.

Type:int, float
roi_names

The names of the ROIs.

Type:list
roi_nominal_angles

The nominal angles of the ROIs; must be same order as roi_names.

Type:list
roi_angles

The ROI angles, corrected for phantom roll.

dist2rois

Distance from the phantom center to the ROIs, corrected for pixel spacing.

roi_radius

ROI radius, corrected for pixel spacing.

get_ROI_vals()[source]

Return a dict of the HU values of the HU ROIs.

plot_rois(axis, threshold=None)[source]

Plot the ROIs to the axis.

class pylinac.ct.HUDiskROI(array, angle, roi_radius, dist_from_center, phantom_center, nominal_value=None, tolerance=None, background_median=None, background_std=None)[source]

Bases: pylinac.core.roi.DiskROI

An HU ROI object. Represents a circular area measuring either HU sample (Air, Poly, …) or HU uniformity (bottom, left, …).

Parameters:
  • nominal_value (int) – The nominal pixel value of the HU ROI.
  • tolerance (int) – The roi pixel value tolerance.
cnr

The contrast-to-noise value of the HU disk

value_diff

The difference in HU between measured and nominal.

passed

Boolean specifying if ROI pixel value was within tolerance of the nominal value.

plot_color

Return one of two colors depending on if ROI passed.

class pylinac.ct.RectangleROI(array, width, height, angle, dist_from_center, phantom_center)[source]

Bases: pylinac.core.geometry.Rectangle

Class that represents a rectangular ROI.

pixel_array

The pixel array within the ROI.

class pylinac.ct.ThicknessROI(array, width, height, angle, dist_from_center, phantom_center)[source]

Bases: pylinac.core.roi.RectangleROI

A rectangular ROI that measures the angled wire rod in the HU linearity slice which determines slice thickness.

long_profile

The profile along the axis perpendicular to ramped wire.

wire_fwhm

The FWHM of the wire in pixels.

plot_color

The plot color.

class pylinac.ct.GeometricLine(geo_roi1, geo_roi2, mm_per_pixel, tolerance)[source]

Bases: pylinac.core.geometry.Line

Represents a line connecting two nodes/ROIs on the Geometry Slice.

nominal_length_mm

The nominal distance between the geometric nodes, in mm.

Type:int, float
Parameters:
  • geo_roi1 (GEO_ROI) – One of two ROIs representing one end of the line.
  • geo_roi2 (GEO_ROI) – The other ROI which is the other end of the line.
  • mm_per_pixel (float) – The mm/pixel value.
  • tolerance (int, float) – The tolerance of the geometric line, in mm.
passed

Whether the line passed tolerance.

pass_fail_color

Plot color for the line, based on pass/fail status.

length_mm

Return the length of the line in mm.

Helper Functions

pylinac.ct.combine_surrounding_slices(dicomstack, nominal_slice_num, slices_plusminus=1, mode='mean')[source]

Return an array that is the combination of a given slice and a number of slices surrounding it.

Parameters:
  • dicomstack (~pylinac.core.image.DicomImageStack) – The CBCT DICOM stack.
  • nominal_slice_num (int) – The slice of interest (along 3rd dim).
  • slices_plusminus (int) – How many slices plus and minus to combine (also along 3rd dim).
  • mode ({'mean', 'median', 'max}) – Specifies the method of combination.
Returns:

combined_array – The combined array of the DICOM stack slices.

Return type:

numpy.array