tomdoel / pulmonarytoolkit

Lung medical image analysis and visualisation software for Matlab.
GNU General Public License v3.0
84 stars 57 forks source link

Freehand editing of airways #49

Open adityaapte opened 3 years ago

adityaapte commented 3 years ago

I would like to edit the airway segments and recalculate radius and center-line for the edited airways. Current options support adding/erasing predetermined patches based on intensity threshold. Is it possible to add regions to airway segments using a freehand polygon drawing tool? As an alternative, is it possible to calculate radius and center-line for manual segmentation?

tomdoel commented 3 years ago

It's not currently supported in the GUI, but could be done with some coding.

It's a little complicated because PTK doesn't directly use the airway segmentation image to compute the radius and centerlines. Instead, the segmentation process creates tree-like data structures where each branch is connected to other branches through Parent/Child properties. This tree is processed to produce a rough centreline tree, and finally this centreline tree is processed in conjunction with the original image to compute a smoothed centreline and the radius measurements.

So, to add or remove branches you would need to create or remove a branch from the tree datastructure that is produced by the PTKAirways plugin. That could be done with scripting or, with a bit more work, implemented as an editing tool on the GUI.

Alternatively, you could modify the segmentation algorithm (PTKAirwayRegionGrowingWithExplosionControl) to give more control over the segmentation process, such as modifying the airway threshold or maybe add some interactive element.

The algorithm has three main stages:

  1. PTKAirways plugin: takes a threshold image and outputs a structured segmented airway tree of PTKTreeSegment objects. Most of the work is done by the library function PTKAirwayRegionGrowingWithExplosionControl.
  2. PTKAirwaySkeleton plugin: compute a skeleton image as a tree of PTKSkeletonSegment objects. Most of the work is done by the library function PTKGetCentrelineFromAirways
  3. PTKAirwayCentreline plugin: uses the tree from 2 to compute a smooth centreline and inner/outer radius. Most of the work is done by the library function PTKGetRadiusForAirways

Worth noting that the function PTKGetRadiusForAirways() function which computes the airway radius does this using FWHM on the original intensity image. So, even if you accurately drew out the contours to add to the segmentation, it wouldn't make much difference to the computed radius values returned by this function.