A few notes taken while reading the github.com/mandykoh/simian
code.
An index is a tree of nodes. Each node contains one or more entries. An entry is (roughly) a thumbnail of a given size, and the corresponding fingerprint. Within a node, entries are accessible by fingerprint.
Fingerprints provide a concept of "distance" between entries, and I guess (haven't read that yet) that the concept is used to make sure that all entries within a node are "closer" to each other than to any of the entries of any other node.
-
created from a JSON file located at some path, e.g.
some/path/example.json
(whatever the extension is, but the file must be valid JSON) -
inside that path, there is also a thumbnail (
.thumb
) named accordingly: e.gsome/path/example.thumb
-
no fingerprint, no attributes are set when creating the entry from a file
-
can also be created from an image, at any arbitrary size
-
in that case, the key is a random 64 character string (hex representation of random 32 bytes)
-
the thumbnail is generated at the given size (double of the
maxFingerprintSize
of the entry -- whatever that is) -
has a fingerprint (why is it called
MaxFingerprint
?)
- is an image.Image
- has a size (the smallest of its dimensions)
- has a size (twice as small as the corresponding thumbnail)
- is a function (specific/arbitrary) of a thumbnail of the given size (twice as small as the corresponding thumbnail for a given entry)
- the function clears the six (magic number) less significant bits of the grayscale component (Y in YCbCr) of each pixel of the image (I think that means ignoring the most detailed information about each pixel of the image, i.e. "blurring" the image).
Each
IndexEntry
has aMaxFingerprint
which is the fingerprint at the highest (ie most detailed) level (half the size of the thumbnail, as you’ve seen). This is used to compare entries with each other as the definitive “similarity”, instead of using the blurred fingerprints, which would be less accurate.We can derive all the lower level fingerprints from the
MaxFingerprint
—at the moment it would require a custom resampler that knows how to resample the Y value samples, so for simplicity, I just re-create the lower level fingerprints using the thumbnail instead. With DCT fingerprints, this derivation becomes pretty trivial, and we can basically replace the thumbnails completely with theMaxFingerprint
.