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

Any reason the ImageHaash.hash's shape is (1, N^2) rather than (N^2)? #79

Open
hj3yoo opened this issue Oct 12, 2018 · 2 comments
Open

Comments

@hj3yoo
Copy link

hj3yoo commented Oct 12, 2018

When I look at this, all of the computations of ImageHash requires flattening out the hash. When I was profiling (for hash_size=32), each of the flattening is adding 0.5us of overhead that can be avoided.
It might be small, but I have code where I need to subtract one hash from 10,000 stored hashes every frame I'm processing, and it adds more than 10ms per frame. This forces me to copy paste the arithmetic of ImageHash to my code snippet (instead of calling some_hash - other_hash)

I don't see any reason to store the flattened version of it in the first place. In other words:

def __init__(self, binary_array):
	self.hash = binary_array.flatten()
@JohannesBuchner
Copy link
Owner

Hmm, I think I did that because one could make hashes of (6,4) or (4,6) in principle. The functions allow one to compare these for convenience because some databases may store the _binary_array_to_hex and hex_to_hash lose the shape information (flattening things). Maybe we could make the .hash field flat in __init__ as you say and add a .shape property?

@hj3yoo
Copy link
Author

hj3yoo commented Oct 15, 2018

It might be a better alternative. You can convert from the proposed fields (self.hash, self.shape) into the original field, too.

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

2 participants