mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-18 03:04:45 +03:00
Add support for difference-aware hash calculation.
Fix indentation exception
This commit is contained in:
parent
998116bf08
commit
96e3c0a853
|
@ -2708,7 +2708,7 @@ class Image:
|
|||
decimal_value = 0
|
||||
return hash_string
|
||||
|
||||
def is_similar_to(self, image, hamming_distance: int = 3) -> bool:
|
||||
def is_similar_to(self, image, hamming_distance: int = 3) -> bool:
|
||||
"""
|
||||
|
||||
:param image: PIL.Image / dHash(str)
|
||||
|
@ -2719,7 +2719,7 @@ def is_similar_to(self, image, hamming_distance: int = 3) -> bool:
|
|||
dis = self.hamming_distance(image)
|
||||
return True if dis <= hamming_distance else False
|
||||
|
||||
def hamming_distance(self, image) -> int:
|
||||
def hamming_distance(self, image) -> int:
|
||||
"""
|
||||
Calculate the Hamming distance between two pictures (based on dHash algorithm)
|
||||
:param image: PIL.Image / dHash(str)
|
||||
|
@ -2734,8 +2734,8 @@ def hamming_distance(self, image) -> int:
|
|||
|
||||
return sum(image1_diff ^ image2_diff)
|
||||
|
||||
@staticmethod
|
||||
def _difference(image):
|
||||
@staticmethod
|
||||
def _difference(image):
|
||||
"""
|
||||
*Private method*
|
||||
Calculate difference sequence
|
||||
|
@ -2756,7 +2756,7 @@ def _difference(image):
|
|||
|
||||
return array(difference)
|
||||
|
||||
def _hamming_distance_with_hash(self, dhash: str) -> int:
|
||||
def _hamming_distance_with_hash(self, dhash: str) -> int:
|
||||
"""
|
||||
*Private method*
|
||||
calculate hamming distance with perceptual hash
|
||||
|
|
Loading…
Reference in New Issue
Block a user