Skip to content

How to open dicom with LoadImage() from Tempfile #1656

Closed
@tugot17

Description

@tugot17

I have a web api in which I want to analyze dicom images. It is defined using FastAPI

The method that gets dicom is defined like this:

@analyze_my_dicom.post("/analyze_my_dicom")
async def analyze_my_dicom(dicom: UploadFile = File(...)):
    
    filename = join(
        dirname(realpath(__file__)), "dicoms", dicom.filename
    )

    try:
        with open(filename, "wb") as buffer:
            shutil.copyfileobj(dicom.file, buffer)

        transform = LoadImaged(keys="image")
        data = {"image": filename}
        image = transform(data)["image"]
        ...

Is there a possibility to use LoadInaged directly on UploadFile, so I don't have to save the object to the memory but can work with it directly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    WG: IOFor the IO working groupquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions