qurit / rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.
MIT License
195 stars 57 forks source link

Enhancement for API use #111

Open VendenIX opened 5 months ago

VendenIX commented 5 months ago

I have implemented significant enhancements to the RTUtils library, which originally required file path dependencies for generating and manipulating RTStructs (Radiotherapy Structures). My contribution specifically addresses the limitation of needing file paths, which was not feasible for API-driven environments where direct file system access is restricted or undesirable.

Key Enhancements:

  1. Memory-Based RTStruct Creation:

    • Developed a new method, create_new_from_memory, which allows RTStructs to be created directly from DICOM datasets already loaded into memory using PyDicom. This enhancement is crucial for deploying the library in server environments where DICOM files are received as streams or over network protocols without storing them on disk.
  2. In-Memory RTStruct Saving:

    • Added the save_to_memory function to the RTStruct class. This method facilitates the generation of RTStructs without needing to write to the filesystem. It saves the RTStruct to a BytesIO stream, which can then be used directly within applications or sent over networks, thus enhancing the usability of the library in distributed systems and cloud applications.
  3. API Compatibility:

    • Adjusted the library to be more compatible with web and cloud-based applications by enabling DICOM processing and RTStruct manipulation entirely in memory, aligning with modern microservices architectures and RESTful API practices.

Use Case in API:

Implemented the enhancements in a REST API setting, where DICOM files are retrieved and processed on-the-fly. The updated library handles DICOM files received from HTTP requests, processes them to generate RTStructs, and optionally uploads them to DICOM servers without intermediate disk I/O, demonstrating the library's enhanced functionality in a live server environment.

It would be great to have a feature like this! Thanks!