|
| 1 | +# Heart Segmentation using Simpleware Medical |
| 2 | + |
| 3 | +This experiment demonstrates cardiac segmentation using Synopsys Simpleware Medical's ASCardio module integrated with PhysioMotion4D. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `SegmentHeartSimpleware` class provides integration between PhysioMotion4D and Synopsys Simpleware Medical for automated heart segmentation. This experiment shows how to: |
| 8 | + |
| 9 | +1. Load cardiac CT images |
| 10 | +2. Segment heart structures using ASCardio |
| 11 | +3. Visualize and analyze the results |
| 12 | +4. Export data for further processing |
| 13 | + |
| 14 | +## Requirements |
| 15 | + |
| 16 | +### Software Requirements |
| 17 | + |
| 18 | +- **Synopsys Simpleware Medical X-2025.06 or later** |
| 19 | + - Default installation path: `C:\Program Files\Synopsys\Simpleware Medical\X-2025.06\` |
| 20 | + - Console mode: `ConsoleSimplewareMedical.exe` (command-line version) |
| 21 | + - ASCardio module license required |
| 22 | + |
| 23 | +- **Python packages** (included in PhysioMotion4D environment): |
| 24 | + - `itk` |
| 25 | + - `numpy` |
| 26 | + - `matplotlib` |
| 27 | + - `pyvista` (optional, for 3D visualization) |
| 28 | + |
| 29 | +### Data Requirements |
| 30 | + |
| 31 | +- Cardiac CT image (3D volume) |
| 32 | +- Recommended: Gated cardiac CT or high-resolution heart scan |
| 33 | +- Format: NIfTI (.nii, .nii.gz) or any ITK-readable format |
| 34 | +- Image should include complete heart anatomy |
| 35 | + |
| 36 | +## Files |
| 37 | + |
| 38 | +- **`simpleware_heart_segmentation.ipynb`**: Main demonstration notebook |
| 39 | +- **`README.md`**: This file |
| 40 | +- **`results/`**: Output directory (created automatically) |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +### Quick Start |
| 45 | + |
| 46 | +1. Open `simpleware_heart_segmentation.ipynb` in Jupyter |
| 47 | +2. Update the `input_image_path` in cell 3 to point to your cardiac CT image |
| 48 | +3. Run all cells sequentially |
| 49 | + |
| 50 | +### Configuration |
| 51 | + |
| 52 | +Before running, configure these parameters in the notebook: |
| 53 | + |
| 54 | +```python |
| 55 | +# Set input image path |
| 56 | +input_image_path = "/path/to/your/cardiac_ct.nii.gz" |
| 57 | + |
| 58 | +# Set custom Simpleware path (if not default) |
| 59 | +custom_simpleware_path = "D:/CustomPath/Simpleware/ConsoleSimplewareMedical.exe" |
| 60 | +``` |
| 61 | + |
| 62 | +### Expected Output |
| 63 | + |
| 64 | +The notebook generates: |
| 65 | + |
| 66 | +1. **Segmentation files** (in `results/`): |
| 67 | + - `heart_labelmap_simpleware.nii.gz` - Complete labelmap with all structures |
| 68 | + - `heart_mask_simpleware.nii.gz` - Binary mask of heart structures |
| 69 | + - `vessels_mask_simpleware.nii.gz` - Binary mask of major vessels |
| 70 | + - `contrast_mask_simpleware.nii.gz` - Contrast-enhanced regions |
| 71 | + |
| 72 | +2. **Visualizations**: |
| 73 | + - 2D slice views with segmentation overlays |
| 74 | + - 3D surface renderings (if PyVista available) |
| 75 | + - Statistical analysis tables |
| 76 | + |
| 77 | +## Segmented Structures |
| 78 | + |
| 79 | +### Heart Structures (Label IDs 1-6) |
| 80 | + |
| 81 | +- **1**: Left Ventricle (LV) |
| 82 | +- **2**: Right Ventricle (RV) |
| 83 | +- **3**: Left Atrium (LA) |
| 84 | +- **4**: Right Atrium (RA) |
| 85 | +- **5**: Myocardium |
| 86 | +- **6**: Heart (combined heart mask) |
| 87 | + |
| 88 | +### Major Vessels (Label IDs 7-10) |
| 89 | + |
| 90 | +- **7**: Aorta |
| 91 | +- **8**: Pulmonary Artery |
| 92 | +- **9**: Right Coronary Artery |
| 93 | +- **10**: Left Coronary Artery |
| 94 | + |
| 95 | +## Workflow Details |
| 96 | + |
| 97 | +### Step-by-Step Process |
| 98 | + |
| 99 | +1. **Preprocessing** (automatic): |
| 100 | + - Resampling to 1.0mm isotropic spacing |
| 101 | + - Intensity normalization if needed |
| 102 | + |
| 103 | +2. **Simpleware Integration**: |
| 104 | + - Input image saved to a temporary NIfTI file |
| 105 | + - ConsoleSimplewareMedical.exe is launched with `--input-file` (NIfTI) and `--input-value` (output directory) |
| 106 | + - The Simpleware script runs ASCardio on the loaded image and exports per-structure masks as MHD |
| 107 | + - PhysioMotion4D assembles the labelmap from the mask files and returns results |
| 108 | + |
| 109 | +3. **Postprocessing** (automatic): |
| 110 | + - Labelmap resampled to original image space |
| 111 | + - Anatomical masks created (heart, vessels, etc.) |
| 112 | + - Optional contrast agent detection |
| 113 | + |
| 114 | +4. **Analysis & Visualization**: |
| 115 | + - Volume calculations for each structure |
| 116 | + - 2D slice visualization |
| 117 | + - 3D surface rendering |
| 118 | + |
| 119 | +### Processing Time |
| 120 | + |
| 121 | +Typical processing times: |
| 122 | +- Small CT (256³ voxels): 2-5 minutes |
| 123 | +- Medium CT (512³ voxels): 5-10 minutes |
| 124 | +- Large CT (1024³ voxels): 10-20 minutes |
| 125 | + |
| 126 | +Times depend on image size, system performance, and Simpleware configuration. |
| 127 | + |
| 128 | +## Troubleshooting |
| 129 | + |
| 130 | +### Common Issues |
| 131 | + |
| 132 | +**Issue**: `FileNotFoundError: Simpleware Medical executable not found` |
| 133 | + |
| 134 | +**Solution**: |
| 135 | +- Verify Simpleware installation |
| 136 | +- Ensure you're using `ConsoleSimplewareMedical.exe` (not `SimplewareMedical.exe`) |
| 137 | +- Update `custom_simpleware_path` in the notebook |
| 138 | +- Check default path: `C:\Program Files\Synopsys\Simpleware Medical\X-2025.06\ConsoleSimplewareMedical.exe`; use `set_simpleware_executable_path()` if installed elsewhere |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +**Issue**: `unrecognised option '-python'` or similar command-line errors |
| 143 | + |
| 144 | +**Solution**: |
| 145 | +- Use `ConsoleSimplewareMedical.exe` (console version), not `SimplewareMedical.exe` (GUI version) |
| 146 | +- The script is automatically called with `--run-script` flag |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +**Issue**: `ImportError: Failed to import Simpleware modules` |
| 151 | + |
| 152 | +**Solution**: |
| 153 | +- Ensure ASCardio module is licensed |
| 154 | +- Verify Simpleware version is X-2025.06 or later |
| 155 | +- Check that console mode is properly installed |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +**Issue**: `WARNING: No segmentation masks were created` or missing masks |
| 160 | + |
| 161 | +**Solution**: |
| 162 | +- Ensure the input NIfTI is passed correctly via `--input-file` so Simpleware has an active document |
| 163 | +- Check that ASCardio completed successfully (inspect Simpleware stdout in debug logging) |
| 164 | +- Verify input image contains clear heart anatomy and adequate contrast |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +**Issue**: Input image quality issues |
| 169 | + |
| 170 | +**Solution**: |
| 171 | +- Verify input image contains heart anatomy |
| 172 | +- Check image contrast and quality |
| 173 | +- Ensure proper field of view (complete heart visible) |
| 174 | +- Try adjusting image preprocessing parameters |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +**Issue**: Segmentation timeout after 600 seconds |
| 179 | + |
| 180 | +**Solution**: |
| 181 | +- Image may be too large; consider downsampling |
| 182 | +- Check system resources (CPU, RAM) |
| 183 | +- Increase timeout in `segment_heart_simpleware.py` if needed |
| 184 | + |
| 185 | +--- |
| 186 | + |
| 187 | +**Issue**: Poor segmentation quality |
| 188 | + |
| 189 | +**Solution**: |
| 190 | +- Ensure image has adequate contrast |
| 191 | +- Use contrast-enhanced CT if available |
| 192 | +- Check that heart is centered in field of view |
| 193 | +- Verify image orientation is correct |
| 194 | + |
| 195 | +### Debug Mode |
| 196 | + |
| 197 | +Enable detailed logging: |
| 198 | + |
| 199 | +```python |
| 200 | +import logging |
| 201 | +segmenter = SegmentHeartSimpleware(log_level=logging.DEBUG) |
| 202 | +``` |
| 203 | + |
| 204 | +This provides: |
| 205 | +- Detailed subprocess output |
| 206 | +- Simpleware script messages |
| 207 | +- File I/O operations |
| 208 | +- Timing information |
| 209 | + |
| 210 | +## Integration with Other Workflows |
| 211 | + |
| 212 | +This experiment can be combined with other PhysioMotion4D workflows: |
| 213 | + |
| 214 | +### 4D Heart Animation |
| 215 | +Use segmentation results with `Heart-GatedCT_To_USD` workflow: |
| 216 | +```python |
| 217 | +# After segmentation |
| 218 | +from physiomotion4d.workflow_convert_heart_gated_ct_to_usd import WorkflowConvertHeartGatedCTToUSD |
| 219 | + |
| 220 | +workflow = WorkflowConvertHeartGatedCTToUSD() |
| 221 | +workflow.set_static_labelmap(result["labelmap"]) |
| 222 | +# Continue with 4D USD generation |
| 223 | +``` |
| 224 | + |
| 225 | +### Statistical Model Registration |
| 226 | +Register segmentation with heart model using `Heart-Statistical_Model_To_Patient`: |
| 227 | +```python |
| 228 | +from physiomotion4d.workflow_register_heart_model_to_patient import WorkflowRegisterHeartModelToPatient |
| 229 | + |
| 230 | +workflow = WorkflowRegisterHeartModelToPatient() |
| 231 | +workflow.set_patient_segmentation(result["labelmap"]) |
| 232 | +# Perform model-to-patient registration |
| 233 | +``` |
| 234 | + |
| 235 | +### Custom Analysis |
| 236 | +Extract specific structures for analysis: |
| 237 | +```python |
| 238 | +# Get left ventricle only |
| 239 | +lv_mask = np.where(labelmap_array == 1, 1, 0) |
| 240 | + |
| 241 | +# Calculate LV volume |
| 242 | +lv_volume_ml = np.sum(lv_mask) * voxel_volume / 1000 |
| 243 | + |
| 244 | +# Create mesh for computational modeling |
| 245 | +from physiomotion4d.convert_vtk_to_usd import create_mesh_from_mask |
| 246 | +lv_mesh = create_mesh_from_mask(lv_mask) |
| 247 | +``` |
| 248 | + |
| 249 | +## Performance Optimization |
| 250 | + |
| 251 | +### For Faster Processing |
| 252 | + |
| 253 | +1. **Reduce image resolution**: |
| 254 | +```python |
| 255 | +# Before segmentation |
| 256 | +segmenter.set_target_spacing(2.0) # Use 2mm instead of 1mm |
| 257 | +``` |
| 258 | + |
| 259 | +2. **Use region of interest**: |
| 260 | +```python |
| 261 | +# Crop image to heart region before segmentation |
| 262 | +from physiomotion4d.image_tools import crop_to_roi |
| 263 | +cropped_image = crop_to_roi(input_image, roi_bounds) |
| 264 | +``` |
| 265 | + |
| 266 | +## References |
| 267 | + |
| 268 | +- **Simpleware Medical Documentation**: See Synopsys user manual |
| 269 | +- **ASCardio Module**: Refer to ASCardio technical documentation |
| 270 | +- **PhysioMotion4D**: Main repository documentation |
| 271 | + |
| 272 | +## Citation |
| 273 | + |
| 274 | +If using this integration in research, please cite: |
| 275 | +- Synopsys Simpleware Medical |
| 276 | +- PhysioMotion4D framework |
| 277 | +- Any relevant papers using ASCardio segmentation |
| 278 | + |
| 279 | +## License |
| 280 | + |
| 281 | +This integration code follows the PhysioMotion4D license. Simpleware Medical and ASCardio are commercial products requiring separate licenses from Synopsys. |
| 282 | + |
| 283 | +## Support |
| 284 | + |
| 285 | +For issues with: |
| 286 | +- **PhysioMotion4D integration**: Submit issue to PhysioMotion4D repository |
| 287 | +- **Simpleware Medical/ASCardio**: Contact Synopsys support |
| 288 | +- **This experiment**: Check troubleshooting section above |
| 289 | + |
| 290 | +## Version History |
| 291 | + |
| 292 | +- **v0.2.0** (2026-02-06): Documentation and alignment with current implementation |
| 293 | + - README reflects actual notebook name (`simpleware_heart_segmentation.ipynb`) and correct label IDs (heart 1–6, vessels 7–10) |
| 294 | + - Workflow description updated for `--input-file` (NIfTI) and `--input-value` (output dir) invocation |
| 295 | + - Removed obsolete “placeholder output” limitation; integration works as expected |
| 296 | +- **v0.1.0** (2026-02-04): Initial implementation |
| 297 | + - Basic ASCardio integration |
| 298 | + - Heart and vessel segmentation |
| 299 | + - 2D/3D visualization |
0 commit comments