API Reference
This section provides detailed API documentation for all MedTDA modules and classes.
Overview
MedTDA is organized into several key modules:
featureextractor - Main interface for TDA feature extraction
preprocessor - Image preprocessing utilities
ph_computer - Persistent homology computation
barcodeextractor - Raw barcode extraction
vectorizers - Methods to convert barcodes to feature vectors
loaders - Image and mask loading/saving
utils - General utility functions
cli - Command-line interface
Typical Usage Pattern
The typical workflow uses the FeatureExtractor class as the main interface:
from medtda import FeatureExtractor
# Initialize with configuration
extractor = FeatureExtractor(
vectorization_method='PersImage',
normalize=True
)
# Extract features
features = extractor.execute('image.nii.gz', mask='mask.nii.gz')
For more control, you can use individual components:
from medtda import Preprocessor, BarcodeExtractor
from medtda.vectorizers import persistence_image
# Step-by-step processing
preprocessor = Preprocessor(normalize=True)
processed_image, _ = preprocessor.preprocess(image, mask)
extractor = BarcodeExtractor()
barcodes = extractor.execute(processed_image)
features = persistence_image(barcodes['H1'])
Module Documentation
Core Classes
FeatureExtractor
The main interface for TDA feature extraction. See FeatureExtractor for details.
Key methods:
execute(image, mask=None)- Extract features from an imageset_vectorization_method(method, **params)- Change vectorization methodenable_vectorization_methods(methods)- Enable multiple methods
Preprocessor
Handles image preprocessing operations. See Preprocessor for details.
Key methods:
preprocess(image, mask=None)- Apply all preprocessing stepsIndividual methods for normalization, resampling, windowing, etc.
BarcodeExtractor
Extracts raw persistence barcodes. See BarcodeExtractor for details.
Key methods:
extract(image)- Compute persistence barcodesset_filtration_type(filtration_type)- Change filtration typeset_construction(construction)- Change construction method
Vectorization Functions
MedTDA provides 8 different vectorization methods as standalone functions:
Function |
Description |
|---|---|
|
Statistical summaries (mean, std, min, max, etc.) |
|
Betti numbers as function of filtration value |
|
2D histogram weighted by persistence |
|
Functional representation using landscapes |
|
Average persistence landscape |
|
Information-theoretic features |
|
Distribution of feature lifespans |
|
Tropical algebra representation |
See Vectorizers for detailed documentation of each method.
Utility Functions
The utils module provides various helper functions:
resample_image()- Image resamplingnormalize_image()- Intensity normalizationapply_mask()- Apply binary maskcrop_to_roi()- Crop to region of interestextract_label_from_mask()- Extract single label from multi-label mask
See Utils for complete documentation.
Image Loading and Saving
The loaders module handles I/O operations:
load_image(path)- Load 2D or 3D images (NIFTI, PNG, TIFF, etc.)load_mask(path)- Load binary or multi-label maskssave_image(array, path)- Save images to diskValidation functions for images and masks
See Loaders for complete documentation.
Command-Line Interface
The cli module provides the command-line interface:
create_parser()- Create argument parserprocess_single_file(args)- Process single imageprocess_batch(args)- Process batch of imagesmain()- Main entry point
See CLI for complete documentation.