Medical image analysis toolkit providing algorithms for segmentation, registration, and processing of medical images
—
ITK provides comprehensive algorithms for medical image segmentation, including region growing, level set methods, clustering techniques, and watershed segmentation. These algorithms enable identification and classification of anatomical structures in medical images.
Segments connected regions based on intensity thresholds.
template<typename TInputImage, typename TOutputImage>
class ConnectedThresholdImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
typedef ConnectedThresholdImageFilter Self;
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Seed points
void SetSeed(const IndexType & seed);
void AddSeed(const IndexType & seed);
void ClearSeeds();
// Threshold values
void SetLower(const InputImagePixelType & thresh);
void SetUpper(const InputImagePixelType & thresh);
itkGetConstMacro(Lower, InputImagePixelType);
itkGetConstMacro(Upper, InputImagePixelType);
// Output values
void SetReplaceValue(const OutputImagePixelType & value);
itkGetConstMacro(ReplaceValue, OutputImagePixelType);
// Connectivity
void SetConnectivity(ConnectivityEnumType connectivity);
itkGetConstMacro(Connectivity, ConnectivityEnumType);
};Adaptive region growing with automatic threshold computation.
template<typename TInputImage, typename TOutputImage>
class ConfidenceConnectedImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
typedef ConfidenceConnectedImageFilter Self;
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Seed points
void SetSeed(const IndexType & seed);
void AddSeed(const IndexType & seed);
void ClearSeeds();
// Confidence parameters
void SetMultiplier(double multiplier);
itkGetConstMacro(Multiplier, double);
void SetNumberOfIterations(unsigned int numberOfIterations);
itkGetConstMacro(NumberOfIterations, unsigned int);
// Output value
void SetReplaceValue(const OutputImagePixelType & value);
itkGetConstMacro(ReplaceValue, OutputImagePixelType);
// Computed statistics
itkGetConstMacro(Mean, InputRealType);
itkGetConstMacro(Variance, InputRealType);
// Initial neighborhood radius
void SetInitialNeighborhoodRadius(unsigned int radius);
itkGetConstMacro(InitialNeighborhoodRadius, unsigned int);
};Region growing between two seed points with automatic threshold selection.
template<typename TInputImage, typename TOutputImage>
class IsolatedConnectedImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
typedef IsolatedConnectedImageFilter Self;
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Seed points
void SetSeed1(const IndexType & seed);
void SetSeed2(const IndexType & seed);
void AddSeed1(const IndexType & seed);
void AddSeed2(const IndexType & seed);
void ClearSeeds1();
void ClearSeeds2();
// Threshold bounds
void SetLower(const InputImagePixelType & thresh);
void SetUpper(const InputImagePixelType & thresh);
itkGetConstMacro(Lower, InputImagePixelType);
itkGetConstMacro(Upper, InputImagePixelType);
// Output values
void SetReplaceValue(const OutputImagePixelType & value);
itkGetConstMacro(ReplaceValue, OutputImagePixelType);
// Results
itkGetConstMacro(IsolatedValue, InputImagePixelType);
itkGetConstMacro(IsolatedValueTolerance, InputImagePixelType);
void SetIsolatedValueTolerance(const InputImagePixelType & tolerance);
// Search direction
void SetFindUpperThreshold(bool findUpperThreshold);
itkGetConstMacro(FindUpperThreshold, bool);
};Base class for level set segmentation methods.
template<typename TInputImage, typename TFeatureImage, typename TOutputPixelType>
class SegmentationLevelSetImageFilter : public SparseFieldLevelSetImageFilter<TInputImage, TOutputPixelType>
{
public:
typedef SegmentationLevelSetImageFilter Self;
typedef SparseFieldLevelSetImageFilter<TInputImage, TOutputPixelType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
// Feature image
virtual void SetFeatureImage(const FeatureImageType * featureImage);
const FeatureImageType * GetFeatureImage() const;
// Speed image
virtual void SetSpeedImage(const SpeedImageType * speedImage);
const SpeedImageType * GetSpeedImage() const;
// Advection image
virtual void SetAdvectionImage(const VectorImageType * advectionImage);
const VectorImageType * GetAdvectionImage() const;
// Level set function parameters
void SetMaximumCurvatureTimeStep(double maxTimeStep);
void SetMaximumPropagationTimeStep(double maxTimeStep);
itkGetConstMacro(MaximumCurvatureTimeStep, double);
itkGetConstMacro(MaximumPropagationTimeStep, double);
// Term weights
void SetCurvatureScaling(ValueType curvatureScaling);
void SetPropagationScaling(ValueType propagationScaling);
void SetAdvectionScaling(ValueType advectionScaling);
itkGetConstMacro(CurvatureScaling, ValueType);
itkGetConstMacro(PropagationScaling, ValueType);
itkGetConstMacro(AdvectionScaling, ValueType);
// Evolution parameters
void SetMaximumRMSError(ValueType maxRMSError);
void SetNumberOfIterations(unsigned int numberOfIterations);
itkGetConstMacro(MaximumRMSError, ValueType);
itkGetConstMacro(NumberOfIterations, unsigned int);
// Initialization
void SetInitialImage(const InitialImageType * initialImage);
};Geodesic active contour segmentation.
template<typename TInputImage, typename TFeatureImage, typename TOutputPixelType>
class GeodesicActiveContourLevelSetImageFilter : public SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType>
{
public:
typedef GeodesicActiveContourLevelSetImageFilter Self;
typedef SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Derivative sigma for feature image gradient
void SetDerivativeSigma(float derivativeSigma);
itkGetConstMacro(DerivativeSigma, float);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Shape detection level set segmentation.
template<typename TInputImage, typename TFeatureImage, typename TOutputPixelType>
class ShapeDetectionLevelSetImageFilter : public SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType>
{
public:
typedef ShapeDetectionLevelSetImageFilter Self;
typedef SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Fast marching method for distance transform and initialization.
template<typename TLevelSet, typename TSpeedImage>
class FastMarchingImageFilter : public ImageToImageFilter<TSpeedImage, TLevelSet>
{
public:
typedef FastMarchingImageFilter Self;
typedef ImageToImageFilter<TSpeedImage, TLevelSet> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Node types
enum LabelType { FarPoint, AlivePoint, TrialPoint };
// Seed points
typedef LevelSetNode<PixelType, itkGetStaticConstMacro(SetDimension)> NodeType;
typedef VectorContainer<unsigned int, NodeType> NodeContainer;
typedef typename NodeContainer::Pointer NodeContainerPointer;
void SetTrialPoints(NodeContainer * trialPoints);
NodeContainerPointer GetTrialPoints();
void SetAlivePoints(NodeContainer * alivePoints);
NodeContainerPointer GetAlivePoints();
// Stopping criteria
void SetStoppingValue(double stoppingValue);
itkGetConstMacro(StoppingValue, double);
// Output size specification
void SetOutputSize(const OutputSizeType & size);
void SetOutputRegion(const OutputRegionType & region);
void SetOutputSpacing(const OutputSpacingType & spacing);
void SetOutputOrigin(const OutputPointType & origin);
void SetOutputDirection(const OutputDirectionType & direction);
// Override connectivity
void SetOverrideOutputInformation(bool overrideOutputInformation);
itkGetConstMacro(OverrideOutputInformation, bool);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void GenerateOutputInformation() ITK_OVERRIDE;
virtual void EnlargeOutputRequestedRegion(DataObject * output) ITK_OVERRIDE;
};Watershed segmentation for region partitioning.
template<typename TInputImage>
class WatershedImageFilter : public ImageToImageFilter<TInputImage, Image<IdentifierType, TInputImage::ImageDimension>>
{
public:
typedef WatershedImageFilter Self;
typedef ImageToImageFilter<TInputImage, Image<IdentifierType, TInputImage::ImageDimension>> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Threshold parameters
void SetThreshold(double threshold);
itkGetConstMacro(Threshold, double);
void SetLevel(double level);
itkGetConstMacro(Level, double);
// Mark watershed line
void SetMarkWatershedLine(bool markWatershedLine);
itkGetConstMacro(MarkWatershedLine, bool);
// Fully connected watersheds
void SetFullyConnected(bool fullyConnected);
itkGetConstMacro(FullyConnected, bool);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Morphological watershed transformation.
template<typename TInputImage, typename TOutputImage>
class MorphologicalWatershedImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
typedef MorphologicalWatershedImageFilter Self;
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Watershed parameters
void SetLevel(InputImagePixelType level);
itkGetConstMacro(Level, InputImagePixelType);
void SetMarkWatershedLine(bool markWatershedLine);
itkGetConstMacro(MarkWatershedLine, bool);
void SetFullyConnected(bool fullyConnected);
itkGetConstMacro(FullyConnected, bool);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void EnlargeOutputRequestedRegion(DataObject * output) ITK_OVERRIDE;
};K-means clustering for image segmentation.
template<typename TInputImage>
class KMeansImageClassificationFilter : public ImageToImageFilter<TInputImage, Image<unsigned char, TInputImage::ImageDimension>>
{
public:
typedef KMeansImageClassificationFilter Self;
typedef ImageToImageFilter<TInputImage, Image<unsigned char, TInputImage::ImageDimension>> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Number of classes
void SetNumberOfClasses(unsigned int numberOfClasses);
itkGetConstMacro(NumberOfClasses, unsigned int);
// Maximum iterations
void SetMaximumNumberOfIterations(unsigned int maximumNumberOfIterations);
itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
// Initial means
void SetClassMeans(const MeansContainer & classMeans);
itkGetConstReferenceMacro(ClassMeans, MeansContainer);
// Results
itkGetConstReferenceMacro(FinalMeans, MeansContainer);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};K-means clustering for scalar images.
template<typename TInputImage, typename TOutputImage>
class ScalarImageKmeansImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
typedef ScalarImageKmeansImageFilter Self;
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Class means
void AddClassWithInitialMean(RealPixelType mean);
void SetClassMeans(const MeansContainer & classMeans);
itkGetConstReferenceMacro(ClassMeans, MeansContainer);
itkGetConstReferenceMacro(FinalMeans, MeansContainer);
// Use non-contiguous labels
void SetUseNonContiguousLabels(bool useNonContiguousLabels);
itkGetConstMacro(UseNonContiguousLabels, bool);
// Image region for sampling
itkSetMacro(ImageRegion, ImageRegionType);
itkGetConstMacro(ImageRegion, ImageRegionType);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Curves evolution level set filter.
template<typename TInputImage, typename TFeatureImage, typename TOutputPixelType>
class CurvesLevelSetImageFilter : public SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType>
{
public:
typedef CurvesLevelSetImageFilter Self;
typedef SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Derivative sigma
void SetDerivativeSigma(float derivativeSigma);
itkGetConstMacro(DerivativeSigma, float);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Threshold-based level set segmentation.
template<typename TInputImage, typename TFeatureImage, typename TOutputPixelType>
class ThresholdSegmentationLevelSetImageFilter : public SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType>
{
public:
typedef ThresholdSegmentationLevelSetImageFilter Self;
typedef SegmentationLevelSetImageFilter<TInputImage, TFeatureImage, TOutputPixelType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Threshold values
void SetUpperThreshold(ValueType upperThreshold);
void SetLowerThreshold(ValueType lowerThreshold);
itkGetConstMacro(UpperThreshold, ValueType);
itkGetConstMacro(LowerThreshold, ValueType);
// Edge weight
void SetEdgeWeight(ValueType edgeWeight);
itkGetConstMacro(EdgeWeight, ValueType);
// Smoothing iterations
void SetSmoothingIterations(int smoothingIterations);
itkGetConstMacro(SmoothingIterations, int);
// Smoothing time step
void SetSmoothingTimeStep(TimeStepType smoothingTimeStep);
itkGetConstMacro(SmoothingTimeStep, TimeStepType);
// Smoothing conductance
void SetSmoothingConductance(ValueType smoothingConductance);
itkGetConstMacro(SmoothingConductance, ValueType);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Voronoi diagram-based segmentation.
template<typename TInputImage, typename TOutputImage, typename TBinaryPriorImage>
class VoronoiSegmentationImageFilter : public VoronoiSegmentationImageFilterBase<TInputImage, TOutputImage, TBinaryPriorImage>
{
public:
typedef VoronoiSegmentationImageFilter Self;
typedef VoronoiSegmentationImageFilterBase<TInputImage, TOutputImage, TBinaryPriorImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Segmentation parameters
void SetMean(double mean);
void SetSTD(double std);
void SetMeanPercentError(double meanPercentError);
void SetSTDPercentError(double stdPercentError);
itkGetConstMacro(Mean, double);
itkGetConstMacro(STD, double);
itkGetConstMacro(MeanPercentError, double);
itkGetConstMacro(STDPercentError, double);
// Take a prior
void TakeAPrior(const BinaryObjectImage * aprior);
// Estimation methods
void GetPixelStatisticsFromPrior();
void SetMeanAndSTD(double mean, double std);
protected:
virtual bool TestHomogeneity(IndexList & Plist) ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};// Define image types
typedef itk::Image<short, 3> InputImageType;
typedef itk::Image<unsigned char, 3> OutputImageType;
// Create segmentation filter
typedef itk::ConnectedThresholdImageFilter<InputImageType, OutputImageType> ConnectedFilterType;
ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();
// Set input image
connectedThreshold->SetInput(inputImage);
// Set seed point
InputImageType::IndexType seed;
seed[0] = 150; seed[1] = 100; seed[2] = 50;
connectedThreshold->SetSeed(seed);
// Set threshold values
connectedThreshold->SetLower(100);
connectedThreshold->SetUpper(200);
// Set output value
connectedThreshold->SetReplaceValue(255);
// Execute segmentation
try {
connectedThreshold->Update();
OutputImageType::Pointer segmentation = connectedThreshold->GetOutput();
} catch (itk::ExceptionObject & error) {
std::cerr << "Segmentation failed: " << error << std::endl;
}// Fast marching initialization
typedef itk::FastMarchingImageFilter<InternalImageType, InternalImageType> FastMarchingFilterType;
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
// Set up seed nodes
typedef FastMarchingFilterType::NodeContainer NodeContainer;
typedef FastMarchingFilterType::NodeType NodeType;
NodeContainer::Pointer seeds = NodeContainer::New();
// Add seed points
NodeType node;
InternalImageType::IndexType seedPosition;
seedPosition[0] = 81; seedPosition[1] = 114; seedPosition[2] = 96;
node.SetValue(-5.0);
node.SetIndex(seedPosition);
seeds->InsertElement(0, node);
fastMarching->SetTrialPoints(seeds);
fastMarching->SetSpeedConstant(1.0);
fastMarching->SetOutputSize(inputImage->GetBufferedRegion().GetSize());
fastMarching->SetOutputRegion(inputImage->GetBufferedRegion());
fastMarching->SetOutputSpacing(inputImage->GetSpacing());
fastMarching->SetOutputOrigin(inputImage->GetOrigin());
fastMarching->SetOutputDirection(inputImage->GetDirection());
// Geodesic active contour segmentation
typedef itk::GeodesicActiveContourLevelSetImageFilter<InternalImageType, InternalImageType> GeodesicActiveContourFilterType;
GeodesicActiveContourFilterType::Pointer geodesicActiveContour = GeodesicActiveContourFilterType::New();
geodesicActiveContour->SetInput(fastMarching->GetOutput());
geodesicActiveContour->SetFeatureImage(gradientMagnitude);
geodesicActiveContour->SetPropagationScaling(2.0);
geodesicActiveContour->SetCurvatureScaling(1.0);
geodesicActiveContour->SetAdvectionScaling(1.0);
geodesicActiveContour->SetMaximumRMSError(0.02);
geodesicActiveContour->SetNumberOfIterations(800);
// Execute segmentation
geodesicActiveContour->Update();// Common segmentation filter instantiations
typedef ConnectedThresholdImageFilter<Image<short,2>, Image<unsigned char,2>> ConnectedThreshold2D;
typedef ConnectedThresholdImageFilter<Image<short,3>, Image<unsigned char,3>> ConnectedThreshold3D;
typedef ConfidenceConnectedImageFilter<Image<short,2>, Image<unsigned char,2>> ConfidenceConnected2D;
typedef ConfidenceConnectedImageFilter<Image<short,3>, Image<unsigned char,3>> ConfidenceConnected3D;
typedef FastMarchingImageFilter<Image<float,2>, Image<float,2>> FastMarching2D;
typedef FastMarchingImageFilter<Image<float,3>, Image<float,3>> FastMarching3D;
typedef GeodesicActiveContourLevelSetImageFilter<Image<float,2>, Image<float,2>> GeodesicActiveContour2D;
typedef GeodesicActiveContourLevelSetImageFilter<Image<float,3>, Image<float,3>> GeodesicActiveContour3D;
typedef WatershedImageFilter<Image<float,2>> Watershed2D;
typedef WatershedImageFilter<Image<float,3>> Watershed3D;
// Level set node types
typedef LevelSetNode<float, 2> LevelSetNode2D;
typedef LevelSetNode<float, 3> LevelSetNode3D;
typedef VectorContainer<unsigned int, LevelSetNode2D> NodeContainer2D;
typedef VectorContainer<unsigned int, LevelSetNode3D> NodeContainer3D;
// Connectivity types
enum ConnectivityEnumType {
FaceConnectivity,
FullConnectivity
};
// Label types for watershed
typedef unsigned long IdentifierType;
typedef Image<IdentifierType, 2> LabelImage2D;
typedef Image<IdentifierType, 3> LabelImage3D;ITK's segmentation framework provides a comprehensive suite of algorithms for medical image segmentation, from simple threshold-based methods to advanced level set and active contour techniques.
Install with Tessl CLI
npx tessl i tessl/cmake-itk