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 = ic.core_opts.image_bits)
#
Create an ISCC Content-Code Image with the latest standard algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixels |
Sequence[int]
|
Normalized image pixels (32x32 flattened gray values). |
required |
bits |
int
|
Bit-length of ISCC Content-Code Image (default 64). |
ic.core_opts.image_bits
|
Returns:
Type | Description |
---|---|
ISCC
|
ISCC object with Content-Code Image. |
gen_image_code_v0(pixels, bits = ic.core_opts.image_bits)
#
Create an ISCC Content-Code Image with algorithm v0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixels |
Sequence[int]
|
Normalized image pixels (32x32 flattened gray values) |
required |
bits |
int
|
Bit-length of ISCC Content-Code Image (default 64). |
ic.core_opts.image_bits
|
Returns:
Type | Description |
---|---|
ISCC
|
ISCC object with Content-Code Image. |
soft_hash_image_v0(pixels, bits = ic.core_opts.image_bits)
#
Calculate image hash from normalized grayscale pixel sequence of length 1024.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixels |
Sequence[int]
|
required | |
bits |
int
|
Bit-length of image hash (default 64). |
ic.core_opts.image_bits
|
Returns:
Type | Description |
---|---|
bytes
|
Similarity preserving Image-Hash digest. |