How to use the imagehash.whash function in ImageHash

To help you get started, we’ve selected a few ImageHash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nxths / ggxrd-match-parser / ggxrd-match-parser.py View on Github external
load_image('mom-display-left.png'),
    load_image('mom-display-right.png'),
]
MOM_MODE_IMAGE_RGB_DIFF_THRESHOLD = 75

CHAR_LEFT_IMAGE_BOX = [7, 24, 7+91, 24+40]
CHAR_RIGHT_IMAGE_BOX = [156, 24, 156+91, 24+40]
CHAR_LEFT_IMAGES = load_char_images('char-images', '-left')
CHAR_RIGHT_IMAGES = load_char_images('char-images', '-right')
CHAR_LEFT_EARLY_IMAGES = load_char_images('char-images-early', '-left')
CHAR_RIGHT_EARLY_IMAGES = load_char_images('char-images-early', '-right')
CHAR_IMAGE_HASH_FUNCTIONS = [
    imagehash.average_hash,
    imagehash.phash,
    imagehash.dhash,
    imagehash.whash,
]
CHAR_IMAGE_HASH_THRESHOLD = 80

MAX_ALPHA = 255
image_with_alpha_pixel_count_cache = {}


def clip_frame_to_image(clip_frame):
    return Image.fromarray(clip_frame.astype('uint8'), 'RGB')

def compare_rgb(img_with_alpha, img):
    img_composite = Image.alpha_composite(img.convert('RGBA'), img_with_alpha).convert('RGB')
    img_diff = ImageChops.difference(img_composite, img)
    total = sum(ImageStat.Stat(img_diff).sum)
    try:
        count = image_with_alpha_pixel_count_cache[img_with_alpha.filename]
github ctxis / CAPE / modules / processing / deduplication.py View on Github external
                hashfunc = lambda img: imagehash.whash(img, mode='db4')
github redaelli / imago-forensics / imago / extractor.py View on Github external
def whash(filename):
    if "image" in magic.from_file(filename, mime=True):
        print ("Calculating wHash of: %s" % (filename,))
        hash = imagehash.whash(Image.open(filename))
        helper.sqlite_insert("wHash",str(hash),os.path.basename(filename))
        return hash
    else:
        print "wHash works only with image images"
        return None
github ctxis / CAPE / modules / processing / deduplication.py View on Github external
"""Creates a new key in the report dict for 
        the deuplicated screenshots.
        """
        self.key = "deduplicated_shots"
        shots = []

        try:
            hashmethod = "whash-db4"
            if hashmethod == 'ahash':
                hashfunc = imagehash.average_hash
            elif hashmethod == 'phash':
                hashfunc = imagehash.phash
            elif hashmethod == 'dhash':
                hashfunc = imagehash.dhash
            elif hashmethod == 'whash-haar':
                hashfunc = imagehash.whash
            elif hashmethod == 'whash-db4':
                hashfunc = lambda img: imagehash.whash(img, mode='db4')

            shots_path = os.path.join(self.analysis_path, "shots")
            if os.path.exists(shots_path):
                screenshots = self.deduplicate_images(userpath=shots_path, hashfunc=hashfunc)
                for screenshot in screenshots:
                    shots.append(screenshot.replace(".jpg",""))
        except Exception as e:
            log.error(e)

        return shots
github universitas / universitas.no / django / apps / photo / file_operations.py View on Github external
def get_imagehashes(fp: Fileish,
                    size=FINGERPRINT_SIZE) -> Dict[str, imagehash.ImageHash]:
    """Calculate perceptual hashes for comparison of identical images"""
    try:
        img = pil_image(fp)
        thumb = img.resize((size, size), PIL.Image.BILINEAR).convert('L')
        return dict(
            ahash=imagehash.average_hash(thumb),
            phash=imagehash.phash(thumb),
            whash=imagehash.whash(thumb),
            dhash=imagehash.dhash(thumb),
        )
    except OSError:  # corrupt image file probably
        return {}
github CIRCL / douglas-quaid / carlhauser_server / FeatureExtractor / picture_hasher.py View on Github external
answer["A_HASH"] = self.check_null_hash(imagehash.average_hash(pil_picture))
            if self.fe_conf.P_HASH.get("is_enabled", False):
                self.logger.debug("P_HASH ... ")
                answer["P_HASH"] = self.check_null_hash(imagehash.phash(pil_picture))
            if self.fe_conf.P_HASH_SIMPLE.get("is_enabled", False):
                self.logger.debug("P_HASH_SIMPLE ... ")
                answer["P_HASH_SIMPLE"] = self.check_null_hash(imagehash.phash_simple(pil_picture))
            if self.fe_conf.D_HASH.get("is_enabled", False):
                self.logger.debug("D_HASH ... ")
                answer["D_HASH"] = self.check_null_hash(imagehash.dhash(pil_picture))
            if self.fe_conf.D_HASH_VERTICAL.get("is_enabled", False):
                self.logger.debug("D_HASH_VERTICAL ... ")
                answer["D_HASH_VERTICAL"] = self.check_null_hash(imagehash.dhash_vertical(pil_picture))
            if self.fe_conf.W_HASH.get("is_enabled", False):
                self.logger.debug("W_HASH ... ")
                answer["W_HASH"] = self.check_null_hash(imagehash.whash(pil_picture))
            if self.fe_conf.TLSH.get("is_enabled", False):
                self.logger.debug("TLSH ... ")
                answer["TLSH"] = self.check_null_hash(tlsh.hash(curr_picture))

        except Exception as e:
            self.logger.error("Error during hashing : " + str(e))

        return answer
github Ashafix / NeuroMario / GameServer.py View on Github external
def calculate_img_hash(self, image):
        """

        :param image:
        :return:
        """
        if isinstance(image, str):
            image = Image.open(image)

        image = image.crop(self.crop_box)

        image_hash = imagehash.whash(image, hash_size=self.hashsize)
        return image_hash

ImageHash

Image Hashing library

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Similar packages