Open timhuff opened 2 years ago
I've also been considering performing research into potentially new methods of image hashing. I think a promising idea is to train a CNN via reinforcement learning. We would need a very wide-ranging dataset but once we have that, it would be trivial to define the fitness function.
Another idea: existing hashing methods might benefit by being pre-processed via a sobel edge detector.
One more: instead of selecting pixels in a "block" via a basic grid, use k-means clustering to define areas of the image that are similar.
@pwlmaciejewski @Eghizio So I haven't worked on my canvas-phash library in ages but it still gets some attention that I could direct this way. The image hash is a problem that I find very interesting and I've been doing a lot of research into methods and optimizations of image hashing. In particular, I've found this article to be very informative.
I was working on bringing this library up to speed with typescript and node 12+ compatibility but, with everything I've learned, I've discovered that the best method to accomplish the use case of this project is an entirely different route.
I believe I can create a streaming phash implementation that utilizes the discrete cosine transform. In the above research, they found that this method is a sort of "best of all worlds" situation. It's twice as fast as the mean block hash that we've each implemented. It results in fewer collision. And similar images have a lower average hamming distance. (by the way, I'm not so sure that the levenshtein distance is a reasonable way to determine distance with these algorithms due to their bitpacking methods - adjacent bits are not necessary related)
This algorithm can be implemented in a streaming fashion, which would mean that a user could hash large databases by utilizing streams with a very low overhead and very good performance.
It seems that this has deviated significantly enough from
imghash
such that it should either be made as a backwards-incompatible major update to this library or that it should be put into its own project (was thinkingfast-phash
).I was wondering if you guys would be interested in working on it / maintaining it. I've located an extremely fast DCT implementation, which means most the work is behind us. I'm fairly sure that a certain property of the DCT enables us to use it in a streaming fashion to produce 128-bit hashes. Naturally, the library will include wrappers for files and buffers and paths and such so that users don't need to deal with streams if they don't want to. Also, I feel that the node requirement should be 16 lts. Even node 14 lts is about to stop being supported. This would also be written with a focus on descriptive typescript types and docstrings so that autocomplete makes things easy.
In my research I also discovered that there are interesting methods through which the hash can become impervious to affine transformations.
I'd enjoy your input and would appreciate the help in ensuring this thing doesn't end up like my last one. This is a function that is useful in many different circumstances and it seems that there is not a library out there that focuses on performance, flexibility, and robustness.