Skip to content

Fix windowing accuracy and optimize MRI volume memory usage#54

Open
Ashutosh0x wants to merge 2 commits intoGoogle-Health:mainfrom
Ashutosh0x:fix/windowing-and-memory-optimization
Open

Fix windowing accuracy and optimize MRI volume memory usage#54
Ashutosh0x wants to merge 2 commits intoGoogle-Health:mainfrom
Ashutosh0x:fix/windowing-and-memory-optimization

Conversation

@Ashutosh0x
Copy link
Copy Markdown

This PR addresses inaccuracies in medical image windowing and resolves Out-of-Memory (OOM) issues for large MRI volumes.

  1. Fixed Windowing Accuracy: Added window_accurate to image_utils.py which implements the correct window range (center +/- half width) and uses rounding to minimize precision loss. This addresses known bugs in the legacy window implementation.
  2. Optimized MRI Memory: Refactored _process_buffered_mri_volume in generic_dicom_handler.py to calculate statistics per-slice and process slices one-by-one using pop(). This allows the garbage collector to free raw slice memory progressively, significantly reducing peak RAM usage for large 3D acquisitions.

- Added window_accurate to image_utils.py with proper range and rounding.
- Updated generic_dicom_handler.py to use centralized window_accurate.
- Optimized _process_buffered_mri_volume in generic_dicom_handler.py to reduce RAM footprint by processing slices one-by-one and calculating statistics per-slice.
- Added conditional check for os.register_at_fork (Unix-only).
- Fixed typing.Self import for Python < 3.11 using typing_extensions.
- Added python/data_processing/window_accurate_test.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant