MCPcopy
hub / github.com/idealo/imagededup / WHash

Class WHash

imagededup/methods/hashing.py:625–691  ·  view source on GitHub ↗

Inherits from Hashing base class and implements wavelet hashing. (Implementation reference: https://fullstackml.com/wavelet-image-hash-in-python-3504fdd282b5) Offers all the functionality mentioned in hashing class. Example: ``` # Wavelet hash for images from imagededu

Source from the content-addressed store, hash-verified

623
624
625class WHash(Hashing):
626 """
627 Inherits from Hashing base class and implements wavelet hashing. (Implementation reference:
628 https://fullstackml.com/wavelet-image-hash-in-python-3504fdd282b5)
629
630 Offers all the functionality mentioned in hashing class.
631
632 Example:
633 ```
634 # Wavelet hash for images
635 from imagededup.methods import WHash
636 whasher = WHash()
637 wavelet_hash = whasher.encode_image(image_file = 'path/to/image.jpg')
638 OR
639 wavelet_hash = whasher.encode_image(image_array = <numpy image array>)
640 OR
641 wavelet_hashes = whasher.encode_images(image_dir = 'path/to/directory') # for a directory of images
642
643 # Finding duplicates:
644 from imagededup.methods import WHash
645 whasher = WHash()
646 duplicates = whasher.find_duplicates(image_dir='path/to/directory', max_distance_threshold=15, scores=True)
647 OR
648 duplicates = whasher.find_duplicates(encoding_map=encoding_map, max_distance_threshold=15, scores=True)
649
650 # Finding duplicates to return a single list of duplicates in the image collection
651 from imagededup.methods import WHash
652 whasher = WHash()
653 files_to_remove = whasher.find_duplicates_to_remove(image_dir='path/to/images/directory',
654 max_distance_threshold=15)
655 OR
656 files_to_remove = whasher.find_duplicates_to_remove(encoding_map=encoding_map, max_distance_threshold=15)
657 ```
658 """
659
660 def __init__(self, verbose: bool = True) -> None:
661 """
662 Initialize wavelet hashing class.
663
664 Args:
665 verbose: Display progress bar if True else disable it. Default value is True.
666 """
667 super().__init__(verbose)
668 self.target_size = (256, 256)
669 self.__wavelet_func = 'haar'
670
671 def _hash_algo(self, image_array):
672 """
673 Get wavelet hash of the input image.
674
675 Args:
676 image_array: numpy array that corresponds to the image.
677
678 Returns:
679 A string representing the wavelet hash of the image.
680 """
681 # decomposition level set to 5 to get 8 by 8 hash matrix
682 image_array = image_array / 255

Callers 2

test_hashing.pyFile · 0.90

Calls

no outgoing calls

Tested by 1