Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite to support different image libs #4

Open
xemle opened this issue Jun 21, 2020 · 0 comments
Open

Rewrite to support different image libs #4

xemle opened this issue Jun 21, 2020 · 0 comments

Comments

@xemle
Copy link

xemle commented Jun 21, 2020

I had problems with different sharp versions (which was solved recently in 1.1.0, thanks). While solving this on my side I came up by splitting the problem into

  • Read and resize image - this could be done by sharp, jimp or canvas
  • Calculate the dct2d - this might be useful for other things if the inverse function is supported
  • Calculate phash - the origin task
  • Encoding of the result

I did some rewrite and came up with https://github.com/xemle/sharp-phash/tree/rewrite-phash

This drops the sharp dependency and the resize of the image up to the customer/client. This is the tricky part of the rewrite for a lib called sharp-phash ¯_(ツ)_/¯

The dct2d was rewritten and aligned with the used variable names of the source https://www.mathworks.com/help/images/ref/dct2.html including the idct2d function based on https://www.mathworks.com/help/images/ref/idct2.html

Old Browsers do not support 64 bit numbers due lack of BigInt support. The hash result are 32 bit high and low values with converters of toBin, toHex and toDec (requires BigInt support).

Since I store and transfer the hash result via JSON documents the result is encoded in 16 byte hex string to save space. The comparison is done char-wise by a 16x16 lookup table. Further, since one major use case is to find similar images, the difference algorithm supports a max bit difference to skip further comparisons if the image differs too much.

RFC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant