Skip to content

ISCC - Image-Code#

A similarity preserving perceptual hash for images.

The ISCC Content-Code Image is created by calculating a discrete cosine transform on normalized image-pixels and comparing the values from the upper left area of the dct-matrix against their median values to set the hash-bits.

Images must be normalized before using gen_image_code. Prepare images as follows:

  • Transpose image according to EXIF Orientation
  • Add white background to image if it has alpha transparency
  • Crop empty borders of image
  • Convert image to grayscale
  • Resize image to 32x32
  • Flatten 32x32 matrix to an array of 1024 grayscale (uint8) pixel values

gen_image_code(pixels, bits = 64) #

Create an ISCC Content-Code Image with the latest standard algorithm.

:param Sequence[int] pixels: Normalized image pixels (32x32 flattened gray values). :param int bits: Bit-length of ISCC Content-Code Image (default 64). :return: ISCC object with Content-Code Image. :rtype: ISCC

gen_image_code_v0(pixels, bits = 64) #

Create an ISCC Content-Code Image with algorithm v0.

:param Sequence[int] pixels: Normalized image pixels (32x32 flattened gray values) :param int bits: Bit-length of ISCC Content-Code Image (default 64). :return: ISCC object with Content-Code Image. :rtype: ISCC

soft_hash_image_v0(pixels, bits = 64) #

Calculate image hash from normalized grayscale pixel sequence of length 1024.

:param Sequence[int] pixels: :param int bits: Bit-length of image hash (default 64). :return: Similarity preserving Image-Hash digest. :rtype: bytes