The combine_hashes_mode
function is designed to combine image hashes using the mode for each bit. This function allows handling multiple hashes generated from similar images while also identifying completely black or white images.
- Combines image hashes: Uses the mode to generate a combined hash from multiple image hashes.
- Checks for black and white images: Identifies if a hash represents a completely black or white image and reports it.
- Error handling: The function includes robust checks to ensure that inputs are valid, raising appropriate exceptions in case of issues.
The function accepts a variable number of arguments:
*hashes
(ImageHash): Hash objects to combine. All hashes must have the same dimensions and must be of typeImageHash
.
- Returns a new
ImageHash
object that represents the combined hash of the provided images.
- Distance 0: The images are identical.
- Distance between 1 and 63: The images are similar but not identical. The greater the distance, the lesser the similarity.
- Distance 64: The images have no similarity.
- ValueError: If no hashes are provided or if the hashes do not have the same dimensions.
- TypeError: If any input is not an
ImageHash
object.
hash1 = imagehash.phash(Image.open("path/to/image1.jpg"))
hash2 = imagehash.phash(Image.open("path/to/image2.jpg"))
combined_hash = combine_hashes_mode(hash1, hash2)
print("Combined hash:", combined_hash)