improve image hashing
This commit is contained in:
+9
-10
@@ -892,7 +892,7 @@ class UncategorisedDicom(models.Model):
|
||||
|
||||
series_instance_uid = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
image_md5_hash = models.CharField(max_length=32, null=True, blank=True)
|
||||
image_blake3_hash = models.CharField(max_length=64, null=True, blank=True)
|
||||
|
||||
created_date = models.DateTimeField(default=timezone.now)
|
||||
|
||||
@@ -901,12 +901,13 @@ class UncategorisedDicom(models.Model):
|
||||
def check_for_duplicates(self, image_hash):
|
||||
duplicate = None
|
||||
|
||||
if obj := UncategorisedDicom.objects.filter(image_md5_hash=image_hash).first():
|
||||
duplicate = obj
|
||||
if obj := UncategorisedDicom.objects.filter(image_blake3_hash=image_hash).first():
|
||||
#duplicate = obj
|
||||
return obj
|
||||
|
||||
print(image_hash)
|
||||
|
||||
if obj := SeriesImage.objects.filter(image_md5_hash=image_hash).first():
|
||||
if obj := SeriesImage.objects.filter(image_blake3_hash=image_hash).first():
|
||||
duplicate = obj
|
||||
|
||||
return duplicate
|
||||
@@ -920,11 +921,11 @@ class UncategorisedDicom(models.Model):
|
||||
|
||||
# if self.check_for_duplicates():
|
||||
# return DuplicateDicom
|
||||
image_hash = get_image_dicom_hash(None, dataset=ds)
|
||||
image_blake3_hash = get_image_dicom_hash(None, dataset=ds, hash_type="blake3", direct_pixel_data=True)
|
||||
|
||||
self.image_md5_hash = image_hash
|
||||
self.image_blake3_hash = image_blake3_hash
|
||||
|
||||
duplicate = self.check_for_duplicates(image_hash)
|
||||
duplicate = self.check_for_duplicates(image_blake3_hash)
|
||||
|
||||
self.basic_dicom_tags = self.get_basic_dicom_tags(dataset=ds)
|
||||
|
||||
@@ -932,10 +933,8 @@ class UncategorisedDicom(models.Model):
|
||||
if duplicate != self:
|
||||
raise DuplicateDicom
|
||||
|
||||
|
||||
|
||||
# Hack for tests
|
||||
if image_hash != "1234":
|
||||
if image_blake3_hash != "1234":
|
||||
super().save(*args, **kwargs) # Call the "real" save() method.
|
||||
|
||||
def get_dicom_info(self):
|
||||
|
||||
Reference in New Issue
Block a user