From c933038b83e05909bb0407fbeab04db09078a448 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 26 Dec 2023 18:04:25 +0000 Subject: [PATCH] . --- generic/models.py | 13 +++++++------ helpers/images.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/generic/models.py b/generic/models.py index 12c242af..a46b81e8 100644 --- a/generic/models.py +++ b/generic/models.py @@ -239,14 +239,15 @@ class SeriesImageBase(models.Model): return info def generate_hashes(self): - image_hash, is_dicom = get_image_hash(self.image, hash_type="md5", direct_pixel_data=False) + with pydicom.dcmread(self.image) as ds: + image_hash, is_dicom = get_image_hash(self.image, dataset=ds, hash_type="md5", direct_pixel_data=False) - self.is_dicom = is_dicom - self.image_md5_hash = image_hash + self.is_dicom = is_dicom + self.image_md5_hash = image_hash - image_blake3_hash, is_dicom = get_image_hash(self.image, hash_type="blake3", direct_pixel_data=True) - self.is_dicom = is_dicom - self.image_blake3_hash = image_blake3_hash + image_blake3_hash, is_dicom = get_image_hash(self.image, dataset=ds, hash_type="blake3", direct_pixel_data=True) + self.is_dicom = is_dicom + self.image_blake3_hash = image_blake3_hash self.save() diff --git a/helpers/images.py b/helpers/images.py index dab0f714..f8f74482 100644 --- a/helpers/images.py +++ b/helpers/images.py @@ -182,13 +182,13 @@ def get_image_dicom_hash(img, dataset=None, hash_type="md5", direct_pixel_data=T hash = hasher.hexdigest() return hash -def get_image_hash(img, hash_type="blake3", direct_pixel_data=True) -> (str, bool): +def get_image_hash(img, dataset=None, hash_type="blake3", direct_pixel_data=True) -> (str, bool): is_dicom = False # Try and read the file as a dicom hash = "1234" try: # and generate a hash from the pixel data - hash = get_image_dicom_hash(img, hash_type=hash_type, direct_pixel_data=direct_pixel_data) + hash = get_image_dicom_hash(img, dataset=dataset, hash_type=hash_type, direct_pixel_data=direct_pixel_data) is_dicom = True # ----