def compute_isometric(self, image: tools.ImageInputType): image = tools.to_image_array(image) if hasattr(self, '_compute_isometric'): # pylint: disable=no-member hashes = self._compute_isometric(image) # type: ignore elif hasattr(self, '_compute_isometric_from_hash'): # pylint: disable=no-member hashes = self._compute_isometric_from_hash( # type: ignore self._compute(image)) else: transforms = tools.get_isometric_transforms(image) for name, transform in transforms.items(): transforms[name] = self._compute(transform) hashes = transforms return { transform_name: self.vector_to_string(vector) for transform_name, vector in hashes.items() }
def compute(self, image: tools.ImageInputType, hash_format='base64') -> typing.Union[str, np.ndarray]: """Compute a hash from an image. Args: image: An image represented as a filepath, a PIL image object, or as an np.ndarray object. If it is an np.ndarray object, it must be in RGB color order (note the OpenCV default is BGR). hash_format: One 'base64', 'hex', or 'vector' """ vector = self._compute(tools.to_image_array(image)) return self.vector_to_string( vector, hash_format=hash_format) if not self.returns_multiple else [ self.vector_to_string(v, hash_format=hash_format) for v in vector ]
def compute_with_quality(self, image: tools.ImageInputType, hash_format='base64') -> typing.Tuple[str, int]: """Compute hash and hash quality from image. Args: image: An image represented as a filepath, a PIL image object, or as an np.ndarray object. If it is an np.ndarray object, it must be in RGB color order (note the OpenCV default is BGR). hash_format: One 'base64' or 'hex' Returns: A tuple of (hash, quality) """ vector, quality = self._compute_with_quality( tools.to_image_array(image)) if hash_format == 'vector': return vector, quality return (self.vector_to_string(vector, hash_format=hash_format), quality) if not self.returns_multiple else ( [self.vector_to_string(v) for v in vector], quality)