improve image hashing
This commit is contained in:
+19
-4
@@ -200,7 +200,18 @@ class SeriesImageBase(models.Model):
|
||||
null=True,
|
||||
)
|
||||
|
||||
# We store two hashes of the dicom data to uniquely identify the file
|
||||
# and allow duplicate detection
|
||||
|
||||
# The first is a md5 hash of the pixel array data
|
||||
# this is used because I can't get the direct pixel data to match from cornerstone
|
||||
# (and struggle to get blake3 working in the browser)
|
||||
image_md5_hash = models.CharField(max_length=32, null=True, blank=True)
|
||||
|
||||
# The second is a blake3 hash of the direct pixel data
|
||||
# This is much faster when using pydicom
|
||||
image_blake3_hash = models.CharField(max_length=64, null=True, blank=True)
|
||||
|
||||
is_dicom = models.BooleanField(default=False)
|
||||
|
||||
removed = models.BooleanField(
|
||||
@@ -231,14 +242,18 @@ class SeriesImageBase(models.Model):
|
||||
"""Override save method to add image hash"""
|
||||
if self.image:
|
||||
if not self.image_md5_hash:
|
||||
image_hash, is_dicom = get_image_hash(self.image)
|
||||
image_hash, is_dicom = get_image_hash(self.image, hash_type="md5", direct_pixel_data=False)
|
||||
|
||||
self.is_dicom = is_dicom
|
||||
self.image_md5_hash = image_hash
|
||||
|
||||
# Hack for tests
|
||||
if image_hash != "12345ABCD":
|
||||
super().save(*args, **kwargs) # Call the "real" save() method.
|
||||
if not self.image_blake3_hash:
|
||||
image_blake3_hash, is_dicom = get_image_hash(self.image, hash_type="blake3", direct_pixel_data=True)
|
||||
self.image_blake3_hash = image_blake3_hash
|
||||
|
||||
## Hack for tests
|
||||
#if image_hash != "12345ABCD":
|
||||
# super().save(*args, **kwargs) # Call the "real" save() method.
|
||||
|
||||
super().save(*args, **kwargs) # Call the "real" save() method.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user