Examples
This section provides practical examples demonstrating how to use MedTDA for various tasks.
Overview
The examples are organized by complexity and use case:
Basic Usage - Get started with simple feature extraction
Advanced Preprocessing - Custom preprocessing workflows
Batch Workflows - Process multiple images efficiently
CLI Workflows - Command-line usage patterns
Tutorial Notebook - Interactive Jupyter notebook
All examples use realistic medical imaging scenarios and follow best practices.
Quick Links
Example |
Description |
|---|---|
Simple feature extraction, masks, different formats |
|
Custom pipelines, ROI analysis, multi-step workflows |
|
CSV batch processing, parallel execution, result analysis |
|
CLI patterns, scripting, pipeline integration |
|
Interactive Jupyter notebook tutorial |
Example Gallery
- Basic Usage
- Advanced Preprocessing
- Batch Workflow
- CLI Workflows
- Basic CLI Usage
- Configuration Files
- Batch Processing
- Output Formats
- Advanced Workflows
- Quality Control
- Filtering and Selection
- Preprocessing Exploration
- Vectorization Parameter Tuning
- Automation Scripts
- Integration with ML Pipelines
- Profiling and Optimization
- Useful Aliases
- Debugging
- Next Steps
- See Also
- Interactive Tutorial
Getting Started
If you’re new to MedTDA, start with:
Basic Usage - Learn the fundamentals
Quick Start - 5-minute quick start guide
Advanced Preprocessing - More control over preprocessing
For Production Use
When deploying MedTDA:
Batch Workflow - Efficient batch processing
CLI Workflows - Integrate with existing pipelines
Example Data
Most examples use placeholder paths. To run them:
Option 1: Use your own data
Replace paths with your medical images:
# Replace this
image_path = 'data/patient001.nii.gz'
# With your actual path
image_path = '/path/to/your/scan.nii.gz'
Option 2: Generate synthetic data
For testing purposes:
import numpy as np
from medtda.loaders import save_image
# Create synthetic 3D image
synthetic_image = np.random.rand(64, 64, 64)
save_image(synthetic_image, 'test_image.nii.gz')
# Create synthetic mask
synthetic_mask = (np.random.rand(64, 64, 64) > 0.5).astype(np.uint8)
save_image(synthetic_mask, 'test_mask.nii.gz')
Option 3: Download sample data
See Installation for links to public medical imaging datasets.
Example Categories
By Task
Classification:
Basic Usage - Extract features for ML
Batch Workflow - Process training/test sets
Regression:
Basic Usage - Continuous outcome prediction
Advanced Preprocessing - Optimize preprocessing
Exploratory Analysis:
Basic Usage - Quick feature inspection
Large-Scale Processing:
Batch Workflow - Hundreds/thousands of images
CLI Workflows - Automation and scripting
By Image Type
CT Scans:
Advanced Preprocessing - CT windowing examples
Basic Usage - CT-specific workflows
MRI:
Basic Usage - Multi-sequence MRI
Advanced Preprocessing - Normalization strategies
Microscopy:
Basic Usage - 2D image analysis
Multi-Modal:
Batch Workflow - Process different modalities
Advanced Preprocessing - Modality-specific preprocessing
Code Patterns
Common Import Pattern
Most examples start with:
from medtda import FeatureExtractor, Preprocessor, BarcodeExtractor
from medtda.loaders import load_image, load_mask
from medtda.vectorizers import persistence_image
import numpy as np
Basic Workflow
Standard processing pattern:
# 1. Load data
image, metadata = load_image('scan.nii.gz')
mask, _ = load_mask('mask.nii.gz')
# 2. Configure extractor
extractor = FeatureExtractor(
normalize=True,
vectorization_method='PersImage'
)
# 3. Extract features
features = extractor.execute(image, mask)
# 4. Use features
# ... machine learning, analysis, etc.
Error Handling
Robust processing:
from medtda import FeatureExtractor
try:
extractor = FeatureExtractor()
features = extractor.execute(image_path, mask_path)
except FileNotFoundError as e:
print(f"File not found: {e}")
except ValueError as e:
print(f"Invalid data: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Next Steps
After exploring examples:
User Guide - Comprehensive user guide
API Reference - Detailed API reference
TDA Theory - Understand the theory
Frequently Asked Questions - Common questions
Contributing Examples
Have a useful example? Contribute!
See Contributing to MedTDA for guidelines on:
Submitting new examples
Improving existing examples
Adding tutorial notebooks
Sharing use cases
Tips for Using Examples
Start Simple
Begin with Basic Usage before complex workflows
Adapt to Your Data
Modify paths, parameters, and methods for your specific case
Experiment
Try different preprocessing and vectorization options
Check Performance
Monitor computation time for large datasets
Validate Results
Always verify that features make sense for your application
See Also
Quick Start - 5-minute tutorial
User Guide - Complete user guide
Command-Line Interface (CLI) - CLI reference
API Reference - API documentation