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

Way to compare image hashes #5

Open
benkasminbullock opened this issue Jul 17, 2017 · 4 comments
Open

Way to compare image hashes #5

benkasminbullock opened this issue Jul 17, 2017 · 4 comments

Comments

@benkasminbullock
Copy link
Contributor

At the moment the module returns image hashes but it doesn't seem to offer a way to compare the hashes of two different images. I request adding the feature of a simple way of comparing images.

@runarbu
Copy link
Owner

runarbu commented Jul 17, 2017

There are currently two ways to compare the hashes. If they are totally equal you can just do a 'eq', but the hashes rarely are totally equal.

If the hash is slightly different you need to compare the Hamming distance like this:

    # Hamming distance. Take two hashes in. 
    # Returns the distance. If distance is below 5 the image is normally equal
    sub hammingdistance {
            my ($a, $b) = @_;

            my $distance = 0;
            for (my $i = 0; $i < 64; $i++) {
                    if ($a->{'hash'}->[$i] != $b->{'hash'}->[$i]) {
                            $distance++;
                    }
    
            }

            return $distance;
    }

The hammingdistance function sold definitely be added and this better documented.

Does this clarifies it, or did you mean on some other way of comparing images?

@benkasminbullock
Copy link
Contributor Author

I think casual users of the module would find the module much more useful if there was a simple way to compare the hashes, or even an example in the documentation of how to compare the hashes.

@runarbu
Copy link
Owner

runarbu commented Jul 22, 2017

I agree, you are right. The hammingdistance function sold definitely be added and better documented.

Casual users may also be interested in using the hammingdistance function together with Tree::BK to easily do fuzzy matching on a large set of images, so that should be documented too.

@benkasminbullock
Copy link
Contributor Author

If there is anything I can do to assist in getting this done, let me know.

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

No branches or pull requests

2 participants