Network

Handles the network of tube objects created in AirQuant.

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]

network.TubeNetwork

class network.TubeNetwork(skel, options)

Bases: library.AirQuant, matlab.mixin.SetGet

TubeNetwork for managing analysis of a set of tubes in AirQuant.

TubeNetwork creates and manages objects inherited from tube that represent anatomical tubes on 3 dimensional images.

Todo

  • Consider making tubes property protected.

Parameters
  • source (3Darray) – source image, e.g. CT

  • header (struct) – header information from source

  • voxdim[float, float, float] voxel dimensions

  • seg – binary airway segmentation in the same grid space as source dimensions must match with source.

  • skel – skeleton based on segementation with no internal loops in the same grid space as source. Dimensions must match with source .

  • lims – reduced volume indices

  • max_plane_sz – max interpolated slice size

  • plane_sample_sz – interpolated slice pixel size

  • spline_sample_sz – mm interval to sample along branch arclength

  • skel_pointsprivate, list of skeleton points

  • Dmap – float, array private, distance transform of seg

ClassifySegmentationTubes()

Classify seg into its tube components.

Classifies every foreground point of seg to the nearest point in skel. Assigning it to the respective tube.Tube object in tubes.

ColourIndex(vals, options)

Set colours properties per tube segment.

Visualisation utility method to set colours properties per tube segment. It behaves differently depending on quantitative or qualitative input. i.e. change in colourmap style and colourbar tick value style.

..todo:
  • Reinstate set order for colours. e.g. region properties.

Parameters
  • vals (array or cell array) – list of values per tube.

  • types (array or cell array) – OPTIONAL default = ‘’ possible values that vals can take. Leave empty to infer.

  • name (char) – OPTIOANL default = ‘’ name to appear on colourbar label.

  • maptype (char) – OPTIONAL default = ‘’ accepts either ‘’, ‘qua’ or ‘seq’. Leave blank to infer by vals input.

ExportCSV(path)

Export all tubes and their holistic properties and measurements to csv file.

A list of properties from each tube ID, parent, children and generation and method. Stats based on measurements from :attr:stats and :attr:region saved into a single csv file where each tube is represented by a row.

Todo

  • showcase example

Parameters

path (char) – filename to save as.

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.ExportCSV(example_tubenetwork);
ExportOrthoPatches(path, casename, options)

export perpendicular slice patches of all tubes.

See tube.Tube.ExportOrthoPatches() for more detailed information.

Parameters
  • path (str) – path to directory to save the exported patches. The directory will be created if it doesn’t already exist.

  • casename (char) – casename to use as prefix to each patch slice name.

  • genrange (int) – OPTIONAL default = [0 inf] interval

  • considered. (range of generations that should be) –

Example

>>> run CA_base.m;
>>> AQnet.ExportOrthoPatches('patches','example')
GetTubeValues(labelname, labelidx)

get the value of each tube property or stat

Histogram(options)

Plot histogram of tubes.

Note

Consider case where label contains NaNs.

Warning

Behaviour untested for label containing NaNs.

Parameters
  • count. (label = OPTIONAL default = 'generation' set variable to) – if char must be an tube property, tube stats or region field. e.g. ‘generation’, ‘arclength’, ‘lobe’. Can also be vector of length equal to number of tubes in order.

  • labelidx (scalar) – chosen property in label.

  • print (bool) – table.

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.PlotGen();
I2S(I)

Fast specific implementation of MATLAB’s ind2sub.

MakeDistanceTransform()

Compute distance transform of segmentation and save as property Dmap.

MakeTubePatches(options)

Calls tube.Tube.MakePatchSlices() on all objects in the tubes.

Parameters
  • type (char) – OPTIONAL default = ‘both’ either ‘both’, ‘source’ or ‘seg’.

  • usesegcrop (logical) – OPTIONAL default = false use dynamic slicing, vary the size of the plane dependant on tube.Tube.network.seg size at that point.

  • method (char) – OPTIONAL default = ‘cubic’ see interp3 for details.

MakeTubes(glink)

Internal method for making tubes.

This method should be changed for new anatomies to call different types of children of Tube.tube.

Measure(varargin)

run chosen measure class on all tubes. See method tubes.Tube.Measure().

Also calls measurement methods that require all tube measurement methods to be completed to run.

OrthoView(type, options)

View volume using MATLAB’s inbuilt othogonal viewer.

Call MATLAB’s orthosliceViewer for a property that is a 3D array of this class. All params are inferred from the object properties.

Todo

  • look at exposing display range to user.

  • make scrollable by mousewheel

  • refactor to AirQuant superclass

  • investigate saggital view

Parameters
  • type (char) – OPTIONAL default = source property name

  • view. (of 3D array object to) –

Returns

see ___ for more

details.

Return type

  • s (orthosliceViewer)

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.OrthoView();

figure plot - Network OrthoView

ParseRegion(regionkwarg)

visualisation utility method to interpret the region keyword argument

looks for a default region that already exists in tubes in order for the user to effortlessy colour figures without the need to be explicit.

Plot(options)

Very powerful graph visualisation tool of tubes. Can manipulate by label, edge weight and colour.

Parameters
  • shownodes (bool) –

  • labels. (label = OPTIONAL default = 'ID' set edge) – if char must be an tube property, tube stats or region field. e.g. ‘generation’, ‘arclength’, ‘lobe’. Can also be vector of length equal to number of tubes in order.

  • labelidx (scalar) – chosen property in label.

  • weight (char) – thickness. if char must be an tube property, tube stats or region field. e.g. ‘generation’, ‘arclength’, ‘lobe’. Can also be vector of length equal to number of tubes in order.

  • weightidx (scalar) – chosen property in weight.

  • weightfactor (float) – determines the highest scaling of the linethickness.

  • colour (char) – colour labelling. if char must be an tube property, tube stats or region field. e.g. ‘generation’, ‘arclength’, ‘lobe’. Can also be vector of length equal to number of tubes in order.

  • colouridx (scalar) – chosen property in colour.

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.Plot();

figure plot - Network Plot

Plot3(options)

Plot the airway tree in graph form, in 3D. nodes are in in image space. Set gen to the maximum number of generations to show.

Parameters
  • gen (int) – OPTIONAL default = max([obj.tubes.generation]) plot up to which generation. All by default.

  • colour (char) – colour labelling. if char must be an tube property, tube stats or region field. e.g. ‘generation’, ‘arclength’, ‘lobe’. Can also be vector of length equal to number of tubes in order.

  • colouridx (scalar) – chosen property in colour.

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.Plot3();

figure plot - Network Plot3

Plot3D(options)

Plot segmentation surface of all tubes.

Parameters
  • gen (int) – OPTIONAL default = max([obj.tubes.generation]) plot up to which generation. All by default.

  • alpha (float) – OPTIONAL default = 0.3 opacity of surface plot.

  • colourOPTIONAL default = ‘c’ color of surface. Can be any MATLAB accepted color format, e.g. RGB.

  • type (char) – OPTIONAL default = ‘seg’ can be either

  • surface. ('seg' or 'skel'. which to plot) –

  • region

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.Plot3D();

figure plot - Network Plot3D

PlotSpline(options)

Plot the splines of all tubes objects.

Parameters
  • gen (int) – OPTIONAL default = max([obj.tubes.generation]) plot up to which generation. All by default.

  • colour (char) – colour labelling. if char must be an tube property, tube stats or region field. e.g. ‘generation’, ‘arclength’, ‘lobe’. Can also be vector of length equal to number of tubes in order.

  • colouridx (scalar) – chosen property in colour.

Example

>>> run CA_base.m;
>>> figure;
>>> AQnet.PlotSpline();

figure plot - Network PlotSpline

RunAllTubes(tubefunc, varargin)

Call a tube.Tube method to run on all tubes.

Provides progress of for-loop running the method.

Parameters
  • tubefunc (char) – Any method name of tubes object.

  • varargin – arguments of called method in tubefunc.

S2I(I1, I2, I3)

Fast specific implementation of MATLAB’s sub2ind.

TubeNetwork(skel, options)

Initialise the TubeNetwork class object.

Optional arguments for initialising relating to segmentation processing and then analysis for methods called later. The spline_sample_sz and plane_sample_sz variables are by default set to half the shortest dimension of the source voxel size.

Parameters
  • skel (3darray) – Binary airway centreline in the same grid space as CT. Dimensions must match with CT

  • source (3darray) – OPTIONAL CT loaded from nifti using niftiread.

  • header (struct) – OPTIONAL CT metadata loaded from nifti using niftiinfo.

  • seg (3darray) – OPTIONAL Binary airway segmentation in the same grid space as CT. Dimensions must match with CT.

  • fillholes (bool) – OPTIONAL default = true whether to fill any holes found in a 2.5D (any 2D orthogonal plane) search.

  • largestCC (bool) – OPTIONAL default = false Only keep the largest connected component in the segmentation.

  • spline_sample_sz (float) – OPTIONAL `default =

  • floor ((min(obj.voxdim))*10) – use for all tubes.

  • plane_sample_sz (float) – OPTIONAL `default =

  • floor – to use for all tubes.

  • max_plane_sz (float) – OPTIONAL default =40 max patch size when tubes interpolated in same units as voxel dimensions.

  • originmethod (float) – OPTIONAL default = ‘topnode’ method to set the tube network’s origin. Which will be treated as generation 0. See network.TubeNetwork.Skel2Digraph for options.

TubesAsEdges()

makes the digraph based on tube relationships

TubesAsNodes()

make the digraph with tubes as nodes

Todo

  • Scope for improving efficiency, variables that change

    size.

static load(path)

internal method called when tubenetwork .mat file is loaded.

vol3daxes(ax)

utility function for 3D volumetric plotting. Sets the aspect ratio according to voxel size and reverses the x axes for LPS viewing.

network.ClinicalAirways

class network.ClinicalAirways(varargin)

Bases: network.TubeNetwork

short desc

long desc

Parameters

x (type) –

Return type

y(type)

ClassifyLungLobes()

Attempt to classify airways into their lobes.

Adapted from original algorithm by Gu et al. 2012.

ClinicalAirways(varargin)

short desc

long desc

Parameters

x (type) –

Return type

y(type)

IdentifyCarinaAndTrachea()

short desc

long desc

Parameters

x (type) –

Return type

y(type)