A standardized Python framework for medical image processing.
Project description
Medical Image Standard Library
A standardized Python library for medical image processing, providing abstract interfaces and extensible implementations for DICOM and other medical image formats.
Purpose
Provide standardized abstractions for medical image processing workflows:
- Abstract base classes defining core interfaces (
Image,Algorithm) - Lazy loading pattern for memory-efficient image handling
- Static processing methods for filters, thresholding, and morphology
- Extensible algorithm framework using lambda composition
- Patch-based processing for large images
- GPU acceleration via PyTorch tensors
Architecture Overview
Core Design Principles
- Abstraction-First: Define interfaces through abstract base classes
- Lazy Loading:
__init__()stores metadata,load()loads data - Static Methods: Stateless processing operations
- Composition: Build algorithms from lambda functions
- Extensibility: Easy to add formats, algorithms, and operations
Package Structure
medical_image/
├── data/ # Abstract Image, Patch, PatchGrid, ROI
├── process/ # Static methods: Filters, Threshold, Metrics
├── algorithms/ # Abstract Algorithm, FEBDS implementation
└── utils/ # Error handling, annotations
Design Patterns
The medical-image-std library extensively leverages several core design patterns:
- Strategy & Template Patterns (Algorithms): Algorithms are implemented by inheriting from a base
Algorithmclass and defining their specific execution steps (often using lambda definitions in__init__) and standardizing evaluation through theapply()template method. This allows strategies likeFEBDSorFCMto be swapped interchangeably. - Lazy Loading (Data Management): Image data classes like
DicomImageinitially store only file paths upon creation and defer heavy I/O and memory usage until.load()is invoked. - Static Factories (Processing Operations): Modules like
Filters,Threshold, andMorphologyOperationsoperate statically taking Image inputs without maintaining internal state, ensuring reusability.
📖 Detailed Architecture: See docs/architecture.md
Installation
Requirements
- Python 3.11 or 3.12
- Linux OS
- CUDA GPU (optional)
Install
git clone https://github.com/LATIS-DocumentAI-Group/medical-image-std.git
cd medical-image-std
pip install -r requirements.txt
pip install -e .
Quick Start
1. Load Image (Lazy Loading)
from medical_image.data.dicom_image import DicomImage
# Create object (no data loaded yet)
image = DicomImage("mammogram.dcm")
# Load data when needed
image.load() # ← Lazy loading
# Display and visualize
image.display_info()
image.plot()
2. Apply Processing
from medical_image.process.filters import Filters
from medical_image.process.threshold import Threshold
# Create output image
output = DicomImage("output.dcm")
# Apply filters (static methods)
Filters.gaussian_filter(image, output, sigma=2.0)
Threshold.otsu_threshold(output, output)
# Save result
output.to_png()
3. Use Algorithms
from medical_image.algorithms.FEBDS import FebdsAlgorithm
# Create algorithm (lambda functions defined in __init__)
febds = FebdsAlgorithm(method="dog")
# Apply algorithm sequence
febds.apply(image, output)
4. Patch-based Processing
from medical_image.data.patch import PatchGrid
# Create patch grid (calls _split() automatically)
patch_grid = PatchGrid(image, patch_size=(256, 256))
# Process each patch
for patch in patch_grid.patches:
# Process patch.pixel_data
pass
# Reconstruct
reconstructed = patch_grid.reconstruct()
Key Concepts
Lazy Loading Pattern
- Object Creation:
image = DicomImage("path.dcm")→ Only stores path - Data Loading:
image.load()→ Loads pixel data to memory - Memory Efficient: Load only when needed, clear when done
Static Processing Methods
All processing operations are static methods:
- Filters:
Filters.gaussian_filter(),Filters.median_filter(), etc. - Threshold:
Threshold.otsu_threshold(),Threshold.sauvola_threshold(), etc. - Metrics:
Metrics.entropy(),Metrics.mutual_information(), etc.
Algorithm Framework
Algorithms define processing pipelines:
__init__: Define steps as lambda functionsapply: Execute sequence of lambdas
Example:
class MyAlgorithm(Algorithm):
def __init__(self):
self.step1 = lambda img, out: Filters.gaussian_filter(img, out, sigma=2.0)
self.step2 = lambda img, out: Threshold.otsu_threshold(img, out)
def apply(self, image, output):
self.step1(image, output)
self.step2(output, output)
PatchGrid System
- Automatic splitting:
_split()called in__init__() - Automatic padding: Handles non-divisible dimensions
- Easy reconstruction:
reconstruct()removes padding
Visual Examples
The following section demonstrates the utilization of all clustering and morphological algorithms included with the library on a sample mammogram section (20527054.dcm), capturing an ROI with center (cx=1250, cy=2000) and a half-size of 127.
Base Region Of Interest (ROI)
Algorithm Outputs
Below are the intermediate output visualizations produced by each algorithm when isolating microcalcification structure.
Top-Hat Transform
Enhances brighter elements matching the disk structural element radius.
K-Means Clustering Sequence
Identifies calcifications by hard partitioning pixel frequency and marking the brightest cluster.
FCM Clustering Sequence
Similar to K-Means, but assigns fuzzy membership probabilities to elements to better separate border intensities.
PFCM Typicality Mapping
Averages across noise using cluster typicality measurements, masking out all "atypical" calcified structures apart from dark backgrounds.
FEBDS Output
Uses a hybrid approach of localized difference-of-gaussian (or frequency band-pass) filters and adaptive binarizations.
Documentation
| Document | Description |
|---|---|
| INDEX | Documentation navigation and overview |
| Architecture | Design patterns, diagrams, workflows |
| API Reference | Complete API documentation |
| User Guide | Tutorials and examples |
| Algorithms | Algorithm theory and implementation |
| Datasets | CBIS-DDSM and custom datasets |
| Contributing | Development guide and CI requirements |
| Quick Reference | Code snippets cheat sheet |
Testing
Run Tests
# Run all tests
pytest
# Run CI tests
pytest medical_image/tests/test_dicom.py
# Check formatting
black --check .
CI Requirements
All code must pass CI before merging:
- ✅ Tests pass:
pytest medical_image/tests/test_dicom.py - ✅ Black formatting:
black --check .
Pre-push validation:
pytest medical_image/tests/test_dicom.py && black --check .
📖 CI Details: See docs/contributing.md
Development
Code Formatting
# Format code
black medical_image/
# Check formatting (CI requirement)
black --check .
Adding Features
- New Image Format: Extend
Imageabstract class - New Processing Method: Add static method to appropriate class
- New Algorithm: Extend
Algorithmabstract class
📖 Extension Guide: See docs/architecture.md
Contributing
- Fork the repository
- Create feature branch
- Follow code standards (Black formatting)
- Write tests following existing structure
- Ensure CI passes locally
- Submit pull request
📖 Full Guide: See docs/contributing.md
License
MIT License - See LICENSE file
Links
- Repository: https://github.com/LATIS-DocumentAI-Group/medical-image-std
- Documentation: docs/INDEX.md
Version
Current: 0.2.8.dev1
Quick Navigation
Getting Started → Installation → Quick Start
Learn More → Documentation → Architecture
Contribute → Contributing Guide → CI Requirements
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medical_image_std-0.1.0.tar.gz.
File metadata
- Download URL: medical_image_std-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
400cc062571ea0070e60d980584d31591da5163afaa20ef4c2189099b702b892
|
|
| MD5 |
dc84b47a0f97afb4a08600afccd20f7f
|
|
| BLAKE2b-256 |
4610bcfd1cde7bc827b5d860a9573e72bc774a8a9f8fc7c898afb676a288a884
|
File details
Details for the file medical_image_std-0.1.0-py3-none-any.whl.
File metadata
- Download URL: medical_image_std-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d3dd564a8ffb6ba47aca443d2b96c9f35f665074df95074164b92bc1458c01c
|
|
| MD5 |
7e67930dd4947d9bd46efceebfa4a337
|
|
| BLAKE2b-256 |
72d028cba8f15c07bcf41dcc1d6ed4d2f853f2d9038a935f6aa21d1dd08c00ba
|