Library

Base functions called by AirQuant’s classes.

graph A[handle] --> C(AirQuant) B[matlab.mixin.SetGet] --> C C --> D[Tube] C --> E[Network] D --> F[Airway] E --> G[ClinicalAirways] H[library] I[SuperMeasure] --> J[AirwayFWHMesl] L[AQEllipse]

AirQuant superclass

class library.AirQuant

Bases: handle, matlab.mixin.SetGet, matlab.mixin.Copyable

ParseVolOut(options)

Parse volume of a given property name

Parses the volume of a given property name as output.

Parameters

type (char) – OPTIONAL default = ‘source’. Object property name.

Returns

1 variable * volout(3D array): output volume.

Example

>>> run CA_base.m;
static list_property(someobject, property)

Get the same property for all objects in a list.

Make an array of an object’s property given an array of that object.

Parameters

someobject (object array) – Object cell array.

Returns

1 variable * list(array): output object property array, where ‘’ is

used if that property for a particular object does not exist.

Example

>>> run CA_base.m;
>>> sourcevol = AQnet.ParseVolOut(type='source');
toITKsnap(segname)

View images in ITK-snap medical image viewer.

Open source image and segmentation overlay in ITK-snap (www.itksnap.org). Images are saved as temporary files and then called using system commands to open in ITK-snap.

Parameters

type (char) – OPTIONAL default = ‘seg’. object property name of a segmentation.

Example

>>> run CA_base.m;
>>> AQnet.toITKsnap();
toNii(filename, options)

Save 3D array object property as nifti image.

Parameters
  • filename (char) – name to save as.

  • type (char) – OPTIONAL default = ‘source’ object property that is a 3D array.

  • gz (bool) – OPTIONAL default = true whether to save gzip compress the output.

Example

>>> run CA_base.m;
>>> AQnet.toNii('example');

dataio

library.dataio.CropVol(varargin)

Crop volume to limits or non-zero extremes if bool image.

Crops to boundary with padding of 10 voxels unless this would overextend beyond the boundary of the source image, then it is cropped to the source image boundary.

Todo

  • Make so lims and cropped source can be output together.

Args:

source: source image to be cropped, if only input must be bool lims: OPTIONAL extreme limits to crop volume

Return:

lims: OPTIONAL output if only source provided at input. croppedsource: OPTIONAL cropped source image if lims not given at input.

library.dataio.ParseSeg(seg, options)

Fills holes in segmentation and keeps only the largest connected component.

Parameters

seg – input segmentation

Returns

input segmentation without holes

Return type

robustseg

library.dataio.ReorientVolume(source, meta)

Reorients input volume from niftiinfo/niftiread into forced LPS orientation by applying necessary axes permutations and flips based on the metadata affine.

Parameters
  • img – volume from niftiread

  • meta (struct) – output from niftiinfo for same volume, containing header information

Returns

[output, outvoxdim]

  • output: reoriented volume in LPS configuration

  • outvoxdim: OPTIONAL output voxel dimensions for LPS reorientation.

library.dataio.writeniiaffine(inputfile, aff, offset)

decompress and load

PTKskel

library.PTKskel.MimSaveNiftiAsNifti(image_to_save, path, filename, reporting)

MimSaveAsNifti. Writes out a PTKImage in NIFTI format if originally loaded from NIFTI format using PTK.

Parameters
  • MimSaveNiftiAsNifti (image_data, path, filename, data_type, orientation, reporting) –

  • PTKImage (image_to_save   is a) – to be saved

  • path

  • data. (filename  specify the location to save the NIFTI) –

  • CoreReportingInterface (reporting       an object implementing) – for reporting progress and warnings

Licence:

Part of the TD MIM Toolkit. https://github.com/tomdoel Author: Tom Doel, Copyright Tom Doel 2014. www.tomdoel.com Adapted by Ashkan Pakzad, ashkanpakzad.github.io Distributed under the MIT licence. Please see website for details.

class library.PTKskel.PTKCustomAirwayCentreline

Bases: PTKPlugin

PTKCustomAirwayCentreline by Ashkan Pakzad, 2020. Plugin for finding the centreline of an imported Airway segmentation (i.e. other than that generated by PTKAirways). Based on PTKAirwayCentreline by Tom Doel, 2012.

This is a plugin for the Pulmonary Toolkit. See PTKPlugin.m for more information on how to run plugins. Plugins should not be run directly from your code.

PTKCustomAirwayCentreline calls the PTKAirways plugin to identify the tree structure of the already segmented airways. It then uses the PTKSkeletonise library routine to reduce the airway tree to a centreline and process it inorder to remove internal loops in the airway structure.

The output image is a binary image in the same space as the input segmentation.

Licence:

Part of the TD Pulmonary Toolkit. https://github.com/tomdoel/pulmonarytoolkit Adapted by Ashkan Pakzad, 2020 ashkanpakzad.github.io Author: Tom Doel, 2012. www.tomdoel.com Distributed under the GNU GPL v3 licence. Please see website for details.

library.PTKskel.PTKskel(segpath, seed, saveflag)

SegImagePath is the path to the segmentation image PTK_source is the source directory of PTK which need not be given if PTK is already in the MATLAB search path. add PTK main directory to path if necessary

SimplePTKSkel

library.SimplePTKSkel.AddBorder_adapted(binary_image, border_size)

This is a internal function that has been adepted from object orentated to a spcrited based system

library.SimplePTKSkel.ChangeRawImage_adapted(current_binary_image, new_image)

Adapted function from the PTK code

library.SimplePTKSkel.PTKIsSimplePoint(image)

PTKIsSimplePoint. Determines if a point in a 3D binary image is a simple point.

A point is simple if removing it does not change the local connectivity of the surrounding points.

A faster implementation of this function can be found in PTKFastIsSimplePoint, which uses mex.

Based on algirithm by G Malandain, G Bertrand, 1992

Licence:

Part of the TD Pulmonary Toolkit. https://github.com/tomdoel/pulmonarytoolkit Author: Tom Doel, 2012. www.tomdoel.com Distributed under the GNU GPL v3 licence. Please see website for details.

library.SimplePTKSkel.SkelPTK_windex(binary_image, index_fixed_points)

This function has been apadted from PTKSkeletonise.

graph

library.graph.Compute_Spline_Points(spline, sample_interval)

Computes the parametrised points along a spline at sample interval.

Polynomial splines are defined by discontinuous polynomial functions. They are parametrised by a continuous variable. An interval in parameterised space does not correspond to the same interval in cartesian space. This function identifies the parametrised points for an equidistant spacing along the arclength of the spline.

Parameters
  • spline (struct) – polynomial spline object, e.g. computed using cscvn.

  • sample_interval (scalar) – scalar value defining the sample interval in cartesian space.

Returns

3 items

  • total_arclength (scalar): Total arclength of the spline.

  • parapoints (vector): OPTIONAL parametrised points on spline corresponding to the defined sample interval.

  • arcpoints (vector): OPTIONAL cartesian points on spline corresponding to the defined sample interval.

Example

>>> totalarclength = Compute_Spline_Points(spline);
>>> [totalarclength, para_points, arc_points] = Compute_Spline_Points(spline, sample_interval);
library.graph.skel_2_digraph(skel, method)

Generate digraph from skeleton.

Generate digraph from skeleton using skel2graph library. It is necessary for AirQuant to use a digraph as it dictates the direction that splines are interpolated for tubes. The direction is set by designating an origin node from which all directions in the digraph are oriented away. method topnode selects the highest z-point. The nodes are ordered by a BFS from the origin node.

See https://github.com/phi-max/skel2graph3d-matlab for more details on skel2graph.

Parameters
  • skel – skeleton to turn into digraph

  • method (string) – OPTIONAL method to choose originating direction. default uses topnode method by chossing the most superior node.

Returns

3 items

  • digraph : converted digraph object

  • glink (struct): positional information for each branch relating to skel.

  • gnode (struct): positional information for each node relating to skel.

Example

>>> [digraphout, glink, gnode] = skel_2_digraph(skel, 'topnode')
library.graph.vector_angle(P1, P2, units)

Compute angle of two vectors in either degrees or radians.

Parameters
  • P1 (vector) –

  • P2 (vector) –

  • units (char) – degrees.

Returns

1 variable. * angle(scalar) = angle between the two input degrees in chosen

units.

perpinterp

library.perpinterp.AirwayCenter(raw_image_slice, seg_image_slice)

Check if the centre overlays with the actual segmentation - if not then the new centre will be based at the centre

library.perpinterp.Check_centre_with_segmentation(raw_image_slice, seg_image_slice)

Check if the centre overlays with the actual segmentation - if not then the new centre will be based at the centre

library.perpinterp.Connected_component_region_2d(seed_point, image_slice)

The performs a region growing algorthm to find the connected region. The connected regions is dertermined by a seed. - We assume a 4 neigbourhood array.

library.perpinterp.Find_centre_via_distance_transfrom(binary_image)

The function computes the centre of gravity of the binary slice. Note that the corrdinate system will by row and col NOT x and y. The method is computing the distance transfrom and then find the max.

library.perpinterp.Finding_midpoint_stop(global_ray_profile, mid_threshold, min_limit, max_limit)

Getting the the mid point of the threshold - assumes the ray profile is montonic O - the index of the array

library.perpinterp.Finding_midpoint_stop_right(global_ray_profile, mid_threshold, min_idx, max_idx)

Getting the the mid point of the threshold - assumes the ray profile is montonic

library.perpinterp.Generate_distance_slice(slice_of_interest)

Genrates a map that gives the distence from the centre of the input

library.perpinterp.Grids_coords_for_plane(basis_1, basis_2, centre_point, length_of_plane, sampling_interval)

Genrates that coorindates that we are requires to genreate the intensity

library.perpinterp.Neighbourhood_4_points_for_2D_images(two_d_points, binary_slice)

This gives the neigbouring points on a 2D images - we will assume a four neighbouring points

library.perpinterp.Orthonormal_basis_with_tangent_vector(tangent_vector)

Getting the basis of the vector for the tangent - note that the basis will always be in first basis Source: https://www.amazon.co.uk/Fundamentals-Computer-Graphics-Peter-Shirley/dp/1568814690 The input is the tangent vetor - it always must have three enetries

library.perpinterp.PlaneInterpVol(vol, voxdim, point, normal, options)

short desc

long desc

Parameters
  • vol (single or double) – volume to interpolate.

  • voxdim (triplet) – voxel dimensions of vol

  • point (triplet) – point at which to define interpolation plane.

  • normal (triplet) – normal vector of interpolation plane.

  • plane_szOPTIONAL, default = 80 pixel size of plane.

  • sample_szOPTIONAL, default = 0.5 interpolation sample size.

  • methodOPTIONAL, default = ‘cubic’ interpolation method. see the same arg in MATLAB’s interp3 for more details.

  • offgrid_valOPTIONAL, default = 0 value to set plane pixels that

  • volume. (are out of) –

Return type

out_plane(type)

library.perpinterp.Return_2d_point_from_index(reference_image, list_of_index)

This function returns a list of the 3d points for the coressponding index point

library.perpinterp.Return_centre_pt_image(test_image)

This returns the points of the image coords that atre in the centre - the ouput is in the same crood convention

library.perpinterp.Span_plane_points_from_basis(basis_vector_1, basis_vector_2, coeff_1, coeff_2, phyical_point)

Gives all the points that the basis span from the given coeff.

library.perpinterp.compute_airway_fwhm(source_rays, seg_rays, coords, outlier_removal)

This is to perfrom the ray casting measurents - the input is in a sturct as

The basis of the code is base on the description - Virtual Bronchoscopy for Quantitative Airway Analysis by A P Kiraly et al.

library.perpinterp.ray_cast(interp_source, interp_seg, center, num_rays, ray_interval)

Compute Rays Getting the range limit of the ray which will be the shortest distance from the centre to the bounadry Need to find the limits of the raw

library.perpinterp.spline_normal(spline, para_point)

short desc

long desc

Parameters

x (type) –

Return type

y(type)

Based on original function by Kin Quan 2018 interperate real point on spline

util

library.util.AQ_vertcat(t1, t2)

for vertical concatenation of tables with different columns

library.util.AQdownload_data(dataname)

Get an AirQuant example dataset

Download an AirQuant example dataset if it hasn’t already been downloaded

Parameters

dataname ('char') – name of dataset to download.

Example

>>> AQdownload_data('chestct')
library.util.AQstruct2array(s)

AQSTRUCT2ARRAY Convert structure with doubles to an array. Incase struct2array is not available.

https://uk.mathworks.com/matlabcentral/answers/1717910-was-struct2array-removed-from-matlab Convert structure to cell

library.util.DualIndex(mat, vec1, vec2)

By Ashkan Pakzad 2021 Handles indexing with multiple vectors for a given matrix by utilising sub2ind. Can also handle nan index by eliminating in both inputs.

library.util.I2S3(sz, I)

Convert linear indicies to sub-indices for 3D arrays.

Faster implementation of MATLAB’s ind2sub for 3D arrays only. Reference: https://stackoverflow.com/questions/60954976/fast-general-replacements-for-ind2sub-and-sub2ind-matlab see also ind2sub

Parameters
  • sz – size of reference array e.g. size(3Darray)

  • I – list of linear indices

Returns

list of corresponding 1st sub-indices I2: list of corresponding 2nd sub-indices I3: list of corresponding 3rd sub-indices

Return type

I1

library.util.RunWholeDataset(config)

user can provide config structure with dataset name and this function will populate the ‘casenames’ field with all the cases in that dataset based on the source CT images available.

library.util.S2I3(sz, I1, I2, I3)

Convert sub-indicies to linear indices for 3D arrays.

Faster implementation of MATLAB’s sub2ind for 3D arrays only. inputs I1, I2 and I3 must be the same length. Reference: https://stackoverflow.com/questions/60954976/fast-general-replacements-for-ind2sub-and-sub2ind-matlab see also sub2ind

Parameters
  • sz – size of reference array e.g. size(3Darray)

  • I1 – list of corresponding 1st sub-indices

  • I2 – list of corresponding 2nd sub-indices

  • I3 – list of corresponding 3rd sub-indices

Returns

linear indices of input list

Return type

I

library.util.parse_filename_extension(filename, requiredext)

check extension is requiredext, if not change/set extenesion.