ImagingDataCommons / highdicom

High-level DICOM abstractions for the Python programming language
https://highdicom.readthedocs.io
MIT License
172 stars 37 forks source link

Refactor check for described segments to remove unnecessary copies #221

Closed CPBridge closed 1 year ago

CPBridge commented 1 year ago

Memory utilization is high when constructing segmentations of large images (e.g. WSIs).

This is one simple two-line refactor to reduce memory consumption that I spotted: the current code creates a copy of all non-zero pixels the input array cast to uint16 (which may be double the input array size) just to find the list of unique segments.

Haven't actually evaluated the effect on memory usage (this may not be the limiting factor) but it's so obviously unnecessary that I just fixed it anyway.