Overview

Submodules containing DICOM related functionalities.

To load a single DICOM file, use imfusion.dicom.load_file() and imfusion.dicom.load_folder() to load all series contained in a folder. Both functions return a list of results. In general, each DICOM series is loaded as one Data. This is not always possible though. For example DICOM slices might not stack up in a way representable by a SharedImageSet.

Besides loading DICOMs from the local filesystem, PACS and DicomWeb are supported as well through the imfusion.dicom.load_url() function.

To load a series from PACS, use an URL with the following format: pacs://<hostname>:<port>/<PACS AE title>?series=<series instance uid>&study=<study instance uid> To receive DICOMs from the PACS, a temporary server will be started on the port defined by imfusion.dicom.set_pacs_client_config().

To load a series from a DicomWeb compatible server, use the DicomWeb endpoint (depends on the server), e.g.: https://<hostname>:<port>/dicom-web/studies/<study instance uid>/series/<series instance uid>. If the server requires authentication, a imfusion.dicom.AuthenticationProvider has to be registered. The authentication scheme depends on the server, but here is an example for HTTP Basic Auth with username and password:

class AuthProvider(imfusion.dicom.AuthorizationProvider):
        def __init__(self):
                imfusion.dicom.AuthorizationProvider.__init__(self)
                self.token = ""

        def authorization(self, url):
                return self.token

        def refresh_authorization(self, url, num_failed_requests):
                if acquire_authorization(url, ""):
                        return True
                else:
                        self.token = ""
                        return False

        def acquire_authorization(self, url, message):
                print("Please provide authorization for accessing", url)
                if (message):
                        print(message)

                try:
                        username = input("Username: ")
                        password = getpass.getpass()
                except KeyboardInterrupt:
                        return False

                self.token = "Basic " + base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf=8")
                return True

imfusion.dicom.set_default_authorization_provider(AuthProvider())

imfusion.dicom.load_url("https://example.com/dicom-web/studies/1.2.3.4/series/5.6.7.8")