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

Getting different hashes on bit-for-bit identical PNGs #39

Open
McGeekiest opened this issue Mar 14, 2014 · 9 comments
Open

Getting different hashes on bit-for-bit identical PNGs #39

McGeekiest opened this issue Mar 14, 2014 · 9 comments

Comments

@McGeekiest
Copy link

With two files, shown to be identical via diff, I am getting dramatically different hash values:

$ diff 0_0.png 0_1.png 
$ ruby
require 'rubygems'
require 'phashion'
p1 = Phashion::Image.new('0_0.png')
p2 = Phashion::Image.new('0_1.png')
puts p1.duplicate?(p1) ? "true" : "false"
puts p1.duplicate?(p2) ? "true" : "false"
puts "p1 fingerprint: " + p1.fingerprint.to_s
puts "p2 fingerprint: " + p2.fingerprint.to_s
puts (p1.fingerprint ^ p2.fingerprint).to_s(2).count("1")

Results in:

true
false
p1 fingerprint: 6242629367104429399
p2 fingerprint: 957486519169142254
38

Am I doing something wrong?

@westonplatter
Copy link
Owner

@McGeekiest which phashion version are you on?

@McGeekiest
Copy link
Author

@westonplatter 1.0.6

@westonplatter
Copy link
Owner

ah, I think I know what the problem is.

We made a custom patch to the pHash C library that was released in gem version 1.0.8. The README describes this more, https://github.com/westonplatter/phashion#gem-uses-customized-phash-096.

I'll be pushing an updated 1.1 version this weekend. Until then, you could reference the GitHub master branch. In case it's helpful, more info about how to do that here, #32 (comment).

@McGeekiest
Copy link
Author

Thanks for the help so far, @westonplatter!

$ bundle show | grep phashion
  * phashion (1.0.8 2c6d8c9)

... then I get the same problem in a Rails console. Curiously, the fingerprints on both files differ every time I run the code, as do the hamming distances. I thought maybe there was just an invocation problem; glad to know I wasn't missing something obviously obvious (as it were). :-)

Can I provide any other information to help? I'm on Rails 4.0.2 under Ubuntu Saucy, to start with.

@McGeekiest
Copy link
Author

Oh, hello! Based on the hints in the README, I tried:

$ convert 0_0.png -alpha remove 1_0.png
$ convert 0_1.png -alpha remove 1_1.png

Now it works on the two new PNGs. It's apparently an alpha thing. I'll just write a script to strip alpha information from the PNGs.

@westonplatter
Copy link
Owner

Nice solution.

Sorry @McGeekiest. That's frustrating. I'll have test that and add tests to prove we're catching the alpha-png/regular pngs. Could you send the png images you're using to test? email = my github username [at] gmail

@McGeekiest
Copy link
Author

@westonplatter Done. Let me know if I can help further.

@westonplatter
Copy link
Owner

@McGeekiest tested alpha png images you sent locally, and Phashion said they were duplicates. :(.

I'll update the readme, and talk with @toy to see if he's had coontinued problems with alpha PNGs.

Thanks for the help!

@toaco
Copy link

toaco commented Mar 27, 2019

I'am using phashion 1.2.0 and have encountered a similar problem, the same png image has a different fingerprint, and the console occasionally output:

libpng warning: iCCP: known incorrect sRGB profile

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

3 participants