How lakshyakhandelwal2901/dicom-to-3d-opus works
Purpose and Entry Points
MedRecon Engine is an on-premises Python pipeline that transforms CT DICOM series into surgical-planning meshes, primarily STL or OBJ. The orchestration and Click CLI live in medrecon_engine/main.py; its Python API exposes single-case, anatomy batch, directory batch, pure-HU, and AI workflows. Root scripts such as batch_run.py and triple_obj_pipeline.py are alternate operational drivers.
Input, Validation, and Volume Preparation
The shared front end discovers/loads DICOM series, validates scan resolution constraints, converts pixels to Hounsfield Units, and prepares volumes for downstream processing.
• medrecon_engine/core/volume_loader.py
• medrecon_engine/core/dicom_validator.py
• medrecon_engine/core/hu_converter.py
Classic processing additionally performs configurable smoothing and isotropic resampling; precision limits and HU clipping are centralized in medrecon_engine/config/precision_config.py.
Segmentation Branches
medrecon_engine/main.py selects one of three paths:
• Classic: anatomy-specific segmenters registered through medrecon_engine/anatomy/registry.py, with implementations such as medrecon_engine/anatomy/bone.py and medrecon_engine/anatomy/lung.py.
• Pure HU: multi-structure threshold/morphology segmentation via medrecon_engine/anatomy/hu_segmenter.py, using threshold definitions in medrecon_engine/config/hu_ranges.py.
• AI: DICOM is converted to NIfTI, then TotalSegmentator labels are produced through medrecon_engine/anatomy/ai_segmenter.py; label/group mappings reside in medrecon_engine/config/structure_groups.py.
Adaptive HU and Clinical Analysis
Patient-specific HU histogram analysis can tune segmentation thresholds rather than relying only on fixed ranges. This boundary separates image-derived calibration and findings/report generation from core reconstruction.
• medrecon_engine/hu_model/hu_estimator.py
• medrecon_engine/analysis/hu_analyzer.py
• medrecon_engine/analysis/medical_findings.py
The findings path includes an AI-oriented analyzer at medrecon_engine/analysis/medgemma_analyzer.py, which is optional (--no-ai) and is the main potential external-AI/service boundary.
Mesh Extraction and Processing
Segmentation masks or AI labels become surfaces through VTK-based extraction. Classic/HU flows use volume-oriented marching cubes; AI labels use label-to-mesh conversion. Meshes are then smoothed, decimated, repaired, validated, and, for multi-organ outputs, categorized or merged.
• medrecon_engine/mesh/vtk_generator.py
• medrecon_engine/mesh/mesh_from_labels.py
• medrecon_engine/mesh/mesh_postprocess.py
Quality, Export, and Audit
Validated meshes receive topology and geometric metrics, combined into a confidence score and SURGICAL/USABLE/REJECT grade. Outputs are written as binary/ASCII STL or grouped OBJ, with optional rendered HTML/slice-overlay reports. Each run emits structured JSONL audit records, including failures and reconstruction parameters.
• medrecon_engine/quality/confidence_score.py
• medrecon_engine/export/stl_writer.py
• medrecon_engine/audit/logger.py
Runtime and External Boundaries
The core runtime is Python 3.10+ using SimpleITK, VTK, and NumPy; VTK system libraries are required for rendering. It is designed for local/on-prem execution and Docker deployment, although optional exporters integrate with Azure Blob, Google Cloud Storage, and Google Drive:
• medrecon_engine/export/azure_uploader.py
• medrecon_engine/export/gcs_uploader.py
• medrecon_engine/export/drive_uploader.py
Main entry points: main.py CLI & workflow API · hu_converter.py HU volume converter · hu_segmenter.py Pure-HU segmenter · hu_estimator.py Adaptive HU estimator
Components 21
Entry & orchestration
- CLI & workflow API · Selects single-case, batch, HU, and AI workflows.
medrecon_engine/main.py
Volume preparation
- DICOM series loader
medrecon_engine/core/volume_loader.py - Scan validator · Enforces scan resolution constraints.
medrecon_engine/core/dicom_validator.py - HU volume converter
medrecon_engine/core/hu_converter.py - Precision settings · Controls smoothing, resampling, and HU clipping.
medrecon_engine/config/precision_config.py
Segmentation branches
- Adaptive HU estimator
medrecon_engine/hu_model/hu_estimator.py - Classic anatomy registry · Routes anatomy requests to registered segmenters.
medrecon_engine/anatomy/registry.py - Classic anatomy segmenters · Includes bone and lung implementations.
medrecon_engine/anatomy/bone.py - Pure-HU segmenter · Uses threshold and morphology rules for multiple structures.
medrecon_engine/anatomy/hu_segmenter.py - HU threshold ranges
medrecon_engine/config/hu_ranges.py - TotalSegmentator path · Converts DICOM to NIfTI and produces labels.
medrecon_engine/anatomy/ai_segmenter.py - AI label mappings
medrecon_engine/config/structure_groups.py
Mesh processing
- Volume surface extraction · Marching-cubes extraction for classic and HU masks.
medrecon_engine/mesh/vtk_generator.py - Label-to-mesh conversion · Creates surfaces from AI labels.
medrecon_engine/mesh/mesh_from_labels.py - Mesh post-processing · Smooths, decimates, repairs, validates, and merges meshes.
medrecon_engine/mesh/mesh_postprocess.py
Quality & delivery
- Confidence grading · Scores topology and geometry as SURGICAL, USABLE, or REJECT.
medrecon_engine/quality/confidence_score.py - STL / OBJ export · Writes binary or ASCII STL and grouped OBJ.
medrecon_engine/export/stl_writer.py - Clinical findings analysis · Generates image-derived findings and reports.
medrecon_engine/analysis/medical_findings.py - Optional AI findings · Optional analyzer disabled with --no-ai.
medrecon_engine/analysis/medgemma_analyzer.py - JSONL audit log · Records parameters, outcomes, and failures.
medrecon_engine/audit/logger.py - Optional cloud uploaders · Azure Blob, GCS, and Google Drive integrations.
medrecon_engine/export/azure_uploader.py
Connections 30
- CLI & workflow API → DICOM series loader: starts case or batch
- DICOM series loader → Scan validator: DICOM series
- Scan validator → HU volume converter: validated scan
- Precision settings → HU volume converter: clipping limits
- HU volume converter → Adaptive HU estimator: HU volume
- CLI & workflow API → Classic anatomy registry: classic branch
- HU volume converter → Classic anatomy registry: prepared volume
- Precision settings → Classic anatomy segmenters: smoothing and resampling
- Adaptive HU estimator → Classic anatomy segmenters: adaptive thresholds
- Classic anatomy registry → Classic anatomy segmenters: anatomy selection
- CLI & workflow API → Pure-HU segmenter: pure-HU branch
- HU volume converter → Pure-HU segmenter: prepared volume
- Adaptive HU estimator → Pure-HU segmenter: adaptive thresholds
- HU threshold ranges → Pure-HU segmenter: fixed thresholds
- CLI & workflow API → TotalSegmentator path: AI branch
- DICOM series loader → TotalSegmentator path: DICOM series
- AI label mappings → TotalSegmentator path: label mappings
- Classic anatomy segmenters → Volume surface extraction: segmentation masks
- Pure-HU segmenter → Volume surface extraction: structure masks
- TotalSegmentator path → Label-to-mesh conversion: segmentation labels
- Volume surface extraction → Mesh post-processing: surfaces
- Label-to-mesh conversion → Mesh post-processing: organ meshes
- Mesh post-processing → Confidence grading: validated meshes
- Confidence grading → STL / OBJ export: graded meshes
- Adaptive HU estimator → Clinical findings analysis: histogram analysis
- Clinical findings analysis → Optional AI findings: optional AI analysis
- Confidence grading → JSONL audit log: metrics and grade
- STL / OBJ export → JSONL audit log: artifact outcome
- STL / OBJ export → Optional cloud uploaders: optional upload
- CLI & workflow API → JSONL audit log: parameters and failures