JohannesBuchner / imagehash

A Python Perceptual Image Hashing Module
BSD 2-Clause "Simplified" License
3.28k stars 331 forks source link

Create ImageHash from b16 str #159

Closed linhandev closed 2 years ago

linhandev commented 2 years ago

With this addition we can do

hash = imagehash.ImageHash.from_str( hashlib.md5(img_np.data).hexdigest() )

This way it's easy to create ImageHash from digest generated by other hash libs. Makes processing hashes more uniform.

JohannesBuchner commented 2 years ago

I don't understand why you would input a md5 hash into a perceptual hashing library. Is the point to operate on byte strings? If so, should one not reuse the existing functions and call them in this static function.

linhandev commented 2 years ago

I don't think I understood this part

If so, should one not reuse the existing functions and call them in this static function.

My use case for this was, I generated hashes with this lib and also others. As the ImageHash class has defined subtract to calculate the distance, and also to make the hashes more "uniform", (supporting the the same ops so I can easily loop through them and perform the same ops), I wanted to create ImageHash objects from the digest generated from other libs.

My consideration of using static method was this is likely not a common usecase, and putting these code in init may have negative performance impact?

Just a thought, just close this if you think it's out of scope.

JohannesBuchner commented 2 years ago

I think you can treat such hashes homogeneously by calling hex_to_hash (or hex_to_flathash).