src/perceptual

  Source   Edit

Types

DHash = uint64
DHash is a 64-bit hash, so it's just a synonym for uint64.
Based on the idea described at https://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html This hash is fast to compute and compare (using Hamming distance), and it produces decent results.
  Source   Edit
HHash = distinct uint64
HHash is a 64-bit hash, so it's just a synonym for uint64. However, it should not be compared using popcount, so it's marked as a distinct type.
Basic histogram hash. Can produce a lot of false positives, but it's the most reliable against rotations.
  Source   Edit
MHash = array[0 .. 8, uint64]
MHash is a 576-bit hash, it's represented as an array of 9 uint64 values.
Marr hash, used by pHash library (http://phash.org). Very slow to compute and does not give too reliable results (possibly this is due some issues with this implementation).
  Source   Edit
PHash = uint64
PHash is a 64-bit hash, so it's just a synonym for uint64.
DCT hash, described in http://phash.org/docs/pubs/thesis_zauner.pdf
  Source   Edit
RHash = array[0 .. 4, uint64]
RHash is a 320-bit hash, it's represented as an array of 5 uint64 values.
Radial hash, used by pHash library (http://phash.org). Very slow to compare.
  Source   Edit

Procs

proc `$`(hash: MHash): string {....raises: [ValueError], tags: [].}
Converts MHash to string (hexadecimal) representation.   Source   Edit
proc `$`(hash: RHash): string {....raises: [ValueError], tags: [].}
Converts RHash to string (hexadecimal) representation.   Source   Edit
proc dhash(image: Image): uint64 {....raises: [PixieError], tags: [RootEffect].}
Computes DHash of a given image.   Source   Edit
proc dhash(path: string): DHash {....raises: [PixieError], tags: [RootEffect,
    ReadIOEffect, WriteIOEffect].}
Computes DHash of an image loaded from the given file path.   Source   Edit
proc dhashImg(image: Image): Image {....raises: [PixieError], tags: [RootEffect].}
Converts an image to a debug representation of DHash. Do not use in production.   Source   Edit
proc diff(hash1, hash2: HHash): int {....raises: [], tags: [].}
Compute the difference (Hamming distance) between HHashes. The result is between 0 (identical images) and 240. Usually even the completely different images produce result in 80..100 range and don't go up all the way to 240. Unfortunately, fast popcount won't work here (because histogram hash is actually an array of 16 four-bit integers)   Source   Edit
proc diff(hash1, hash2: MHash): int {....raises: [], tags: [].}
Compute the difference (Hamming distance) between MHashes. The result is between 0 (identical images) and 576. Usually even the completely different images produce result in 270..350 range and don't go up all the way to 576.   Source   Edit
proc diff(hash1, hash2: RHash): float {....raises: [ValueError], tags: [].}
Compute the difference (Hamming distance) between RHashes. Notice that the result is a floating-point value (between 0.0 and 100.0), not an integer. Usually even the completely different images produce result in 75..85 range.   Source   Edit
proc diff(hash1, hash2: uint64): int {....raises: [], tags: [].}
Compute the difference (Hamming distance) between simple 64-bit hashes (like DHash and PHash). Uses popcount instruction. The result is between 0 (identical images) and 64. Usually even the completely different images produce result in 40..50 range and don't go up all the way to 64.   Source   Edit
proc hhash(image: Image; lduplets: int = 7): HHash {....raises: [PixieError],
    tags: [RootEffect].}
Computes HHash of a given image.
lduplets is a number between 0 and 16, and it can be used to control the ratio of luminosity/color information stored in hash:
  • 0 = no bits used for storing luminosity information, 64 bits used for storing color information
  • 7 (default) = 28 (7x4) bits used for storing luminosity information, 36 (64-28) bits used for storing color information
  • 16 = 64 (16x4) bits used for storing luminosity information, no bits used for storing color information
  Source   Edit
proc hhash(path: string): HHash {....raises: [PixieError], tags: [RootEffect,
    ReadIOEffect, WriteIOEffect].}
Computes HHash of an image loaded from the given file path.   Source   Edit
proc hhashImgs(image: Image): tuple[lum, hue: Image] {....raises: [PixieError],
    tags: [RootEffect].}
Converts an image to a debug representation of HHash. Do not use in production.   Source   Edit
proc mhash(image: Image; alpha: int = 2; level: int = 1): MHash {.
    ...raises: [PixieError], tags: [RootEffect].}
Computes MHash of a given image.   Source   Edit
proc mhash(path: string): MHash {....raises: [PixieError], tags: [RootEffect,
    ReadIOEffect, WriteIOEffect].}
Computes MHash of an image loaded from the given file path.   Source   Edit
proc phash(image: Image): uint64 {....raises: [PixieError], tags: [RootEffect].}
Computes PHash of a given image.   Source   Edit
proc phash(path: string): PHash {....raises: [PixieError], tags: [RootEffect,
    ReadIOEffect, WriteIOEffect].}
Computes PHash of an image loaded from the given file path.   Source   Edit
proc phashImg(image: Image): Image {....raises: [PixieError], tags: [RootEffect].}
Converts an image to a debug representation of PHash. Do not use in production.   Source   Edit
proc rhash(image: Image): RHash {....raises: [PixieError], tags: [RootEffect].}
Computes RHash of a given image.   Source   Edit
proc rhash(path: string): RHash {....raises: [PixieError], tags: [RootEffect,
    ReadIOEffect, WriteIOEffect].}
Computes RHash of an image loaded from the given file path.   Source   Edit