.
This commit is contained in:
+9
-7
@@ -238,13 +238,16 @@ class SeriesImageBase(models.Model):
|
|||||||
info = "File is not a dicom."
|
info = "File is not a dicom."
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def generate_hashes(self):
|
def generate_md5_hash(self):
|
||||||
with pydicom.dcmread(self.image) as ds:
|
image_hash, is_dicom = get_image_hash(self.image, hash_type="md5", direct_pixel_data=False)
|
||||||
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.image_md5_hash = image_hash
|
||||||
|
|
||||||
image_blake3_hash, is_dicom = get_image_hash(self.image, dataset=ds, hash_type="blake3", direct_pixel_data=True)
|
self.save()
|
||||||
|
|
||||||
|
def generate_blake3_hash(self):
|
||||||
|
image_blake3_hash, is_dicom = get_image_hash(self.image, hash_type="blake3", direct_pixel_data=True)
|
||||||
self.is_dicom = is_dicom
|
self.is_dicom = is_dicom
|
||||||
self.image_blake3_hash = image_blake3_hash
|
self.image_blake3_hash = image_blake3_hash
|
||||||
|
|
||||||
@@ -253,15 +256,14 @@ class SeriesImageBase(models.Model):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""Override save method to add image hash"""
|
"""Override save method to add image hash"""
|
||||||
if self.image:
|
if self.image:
|
||||||
with pydicom.dcmread(self.image) as ds:
|
|
||||||
if not self.image_md5_hash:
|
if not self.image_md5_hash:
|
||||||
image_hash, is_dicom = get_image_hash(self.image, dataset=ds, hash_type="md5", direct_pixel_data=False)
|
image_hash, is_dicom = get_image_hash(self.image, hash_type="md5", direct_pixel_data=False)
|
||||||
|
|
||||||
self.is_dicom = is_dicom
|
self.is_dicom = is_dicom
|
||||||
self.image_md5_hash = image_hash
|
self.image_md5_hash = image_hash
|
||||||
|
|
||||||
if not self.image_blake3_hash:
|
if not self.image_blake3_hash:
|
||||||
image_blake3_hash, is_dicom = get_image_hash(self.image, dataset=ds, hash_type="blake3", direct_pixel_data=True)
|
image_blake3_hash, is_dicom = get_image_hash(self.image, hash_type="blake3", direct_pixel_data=True)
|
||||||
self.is_dicom = is_dicom
|
self.is_dicom = is_dicom
|
||||||
self.image_blake3_hash = image_blake3_hash
|
self.image_blake3_hash = image_blake3_hash
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user