CaNA (Context-Aware Nodule Augmentation) is a medical imaging toolkit that leverages organ and body segmentation masks as contextual guidance to augment lung nodule segmentation masks. Unlike traditional augmentation methods that may produce anatomically implausible results, CaNA ensures that augmented nodules remain within realistic anatomical boundaries.
- Anatomical Constraint: Uses lung segmentation labels as spatial boundaries
- Context-Aware Processing: Considers surrounding organ structures during augmentation
- Morphological Intelligence: Advanced erosion/dilation with medical domain knowledge
- Quality Assurance: Comprehensive validation and statistical reporting
- Docker (recommended) or Python 3.8+
- 8GB+ RAM for processing medical imaging data
- Input: NIfTI files with lung and nodule segmentations
# Pull the pre-configured container
docker pull ft42/pins:latest
# Clone the repository
git clone https://github.com/your-username/CaNA.git
cd CaNA
# Make scripts executable
chmod +x *.shgit clone https://github.com/your-username/CaNA.git
cd CaNA
# Install dependencies
pip install torch>=2.8.0 monai>=1.4.0 nibabel scikit-image numpy scipy./CaNA_expanded_p150_DLCS24.sh./CaNA_shrinked_p75_DLCS24.shpython CaNA_LungNoduleSize_expanded.py \
--json_path ./demofolder/data/dataset.json \
--dict_to_read "training" \
--data_root ./demofolder/data/ \
--lunglesion_lbl 23 \
--scale_percent 50 \
--mode grow \
--save_dir ./output/expanded/python CaNA_LungNoduleSize_shrinked.py \
--json_path ./demofolder/data/dataset.json \
--dict_to_read "training" \
--data_root ./demofolder/data/ \
--lunglesion_lbl 23 \
--scale_percent 75 \
--save_dir ./output/shrinked/demofolder/
βββ data/
β βββ dataset.json
β βββ vista3Dauto_seg_knneX2mm_GTV_512xy_256z_771p25m/
β βββ DLCS_0001_seg_sh.nii.gz
β βββ DLCS_0002_seg_sh.nii.gz
βββ output/
βββ CaNA_expanded_150_output/
βββ CaNA_shrinked_75_output/
βββ *.csv (statistics)
βββ *.log (processing logs)
{
"training": [
{
"image": "vista3Dauto_seg_knneX2mm_GTV_512xy_256z_771p25m/DLCS_0001_seg_sh.nii.gz",
"label": "vista3Dauto_seg_knneX2mm_GTV_512xy_256z_771p25m/DLCS_0001_seg_sh.nii.gz"
}
]
}| Parameter | Default | Description |
|---|---|---|
--lunglesion_lbl |
23 | Nodule segmentation label |
--lung_labels |
[28,29,30,31,32] | Lung organ labels for context |
--scale_percent |
50/75 | Target size change percentage |
--random_seed |
42 | Reproducibility seed |
--prefix |
Aug23e150_/Aug23s75_ | Output filename prefix |
# Custom lung labels for different datasets
lung_labels = [1, 2, 3] # Adjust based on your segmentation
# Modify morphological operations
structure_element = ball(radius=2) # Smaller/larger structuring element
# Custom scaling factors
expansion_percent = 75 # For 175% final size
shrinking_percent = 60 # For 60% final size- Augmented Masks: Modified NIfTI files with size-adjusted nodules
- Statistics CSV: Comprehensive volume analysis
- Processing Logs: Detailed execution reports
- Quality Metrics: Success rates and error analysis
| File | Original Volume (voxels) | Augmented Volume (voxels) | Achievement Ratio | Target Ratio | Status |
|---|---|---|---|---|---|
| DLCS_0001 | 662 | 971 | 1.47x | 1.50x | β Success |
| DLCS_0002 | 1346 | 1529 | 1.14x | 1.50x | β Controlled |
| DLCS_0002 | 1188 | 1609 | 1.35x | 1.50x | β Success |
Real results from latest CaNA v1.1 testing with DLCS dataset
- Dataset Augmentation: Generate realistic variations for training
- Robustness Testing: Evaluate model performance across size ranges
- Longitudinal Studies: Simulate nodule growth/shrinkage patterns
- Cross-institutional Validation: Test generalizability across different scanners
- Modality: CT scans (NIfTI format)
- Anatomy: Lung nodules and surrounding structures
- Resolution: Multi-resolution support (tested on 512Γ512Γ256)
- Labels: Multi-label segmentation compatibility
- Input Validation: Verify data integrity and format compliance
- Lesion Detection: Connected component analysis for individual nodules
- Context Analysis: Identify surrounding lung structures and boundaries
- Enhanced Morphological Processing: Controlled erosion/dilation with overshoot prevention
- Real-time Monitoring: Progress tracking with iteration-level feedback
- Quality Control: Volume verification, boundary checking, and error recovery
- Output Generation: Create augmented masks with comprehensive logging
- Smart Growth Control: Prevents overshooting target volumes by more than 10%
- Enhanced Boundary Detection: Better handling of complex anatomical constraints
- Detailed Progress Logging: Real-time feedback during processing iterations
- Robust Error Handling: Graceful recovery from boundary conflicts
- Performance Optimization: Improved iteration control and termination logic
The core augmentation uses anatomically-constrained morphological operations:
# Expansion: Original + Dilation within lung boundaries
augmented_mask = original_lesion βͺ (dilate(original_lesion) β© lung_mask)
# Shrinkage: Fill + Eroded subset within lung boundaries
augmented_mask = erode(original_lesion) β© lung_mask- Processing Speed: ~15-22 seconds per nodule (512Γ512Γ256 CT volumes)
- Memory Usage: ~2GB RAM per case (typical workload)
- Volume Accuracy: Β±10% targeting precision with overshoot prevention
- Success Rate: 100% successful augmentations with enhanced control
- Target Achievement:
- Expansion: 1.14x-1.47x achieved (target 1.5x)
- Shrinking: Preserves anatomical integrity
- Boundary Compliance: 100% anatomical constraint adherence
| Component | Minimum | Recommended |
|---|---|---|
| RAM | 8GB | 16GB |
| Storage | 5GB | 20GB |
| CPU | 4 cores | 8+ cores |
| GPU | Not required | CUDA-capable (optional) |
- Technical Report: Detailed methodology and evaluation
- Formatter: Black
- Linter: Flake8
- Type Checking: mypy
- Documentation: Sphinx
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.
Summary:
- β Academic Research: Freely use and modify
- β Educational Use: Include in courses and tutorials
- β Non-commercial Applications: Open source projects welcome
- β Commercial Use: Requires explicit permission
- π Attribution: Must cite original work
- GitHub Issues: Report bugs and request features
- Discussions: Community Q&A
- Email: tushar.ece@duke.edu
- MONAI Team: Foundation medical imaging framework
- PyTorch Community: Deep learning infrastructure
- Docker: Containerization platform
- Medical Imaging Community: Domain expertise and validation