pydicom / deid

best effort anonymization for medical images using python
https://pydicom.github.io/deid/
MIT License
140 stars 43 forks source link

Add 'handler_name' to save_dicom() function #209

Closed AlexanderBunt closed 2 years ago

AlexanderBunt commented 2 years ago

For my project, I want to use GDCM to decompress the images (0.5 sec faster then 'default'). Can we add a parameter for this to the function save_dicom()?

Something like this:

def save_dicom(self, output_folder=None, image_type="cleaned", handler_name=None):
        """save a cleaned dicom to disk. We expose an option to save
        an original (change image_type to "original" to be consistent,
        although this is not incredibly useful given it would duplicate
        the original data.
        """
        # Having clean also means has dicom image
        if hasattr(self, image_type):
            dicom_name = self._get_clean_name(output_folder)
            dicom = read_file(self.dicom_file, force=True)
            # If going from compressed, change TransferSyntax
            if dicom.file_meta.TransferSyntaxUID.is_compressed is True:
                dicom.decompress(handler_name=handler_name)
            dicom.PixelData = self.cleaned.tostring()
            dicom.save_as(dicom_name)
            return dicom_name
        else:
            bot.warning("use detect() --> clean() before saving is possible.")
vsoch commented 2 years ago

@AlexanderBunt what would be the difference between the above and just adding that to be run before save?

AlexanderBunt commented 2 years ago

@AlexanderBunt what would be the difference between the above and just adding that to be run before save?

Thats a good question. Didn't think about that to be honest. Think that will do the trick.