commonsmachinery / blockhash-python

Implementation of perceptual image hash calculation in Python
http://blockhash.io/
MIT License
130 stars 29 forks source link

Tweaked `block_bottom` and `block_right` calculation. #10

Closed dsoprea closed 6 years ago

dsoprea commented 6 years ago
dsoprea commented 6 years ago

I originally thought this was a fix because I was submitted the C implementation fix at the same time and got really happy when the hashes all started agreeing. This is just a simplification. No functional change. It's up to you to merge it if you'd like.

Original:

$ python blockhash.py ~/Downloads/*.jpg
1ffc3fff00fe000021ff7e3f0f8007c03fff1f8d0f9806003ffc3ff80f0400f0  /home/dustin/Downloads/20170618_155330.jpg
1ffc3fff00fe000031ff3e3f0f8007c03fff1f8d0f9806003ffc3ff80f0400f0  /home/dustin/Downloads/20170618_155330-small.jpg
7ff00fe00ff007e00ffd07f807f003f003fc07fa07f413f017f927e261cce0d8  /home/dustin/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers.jpg
7ff00fe00fe007f00ffd07f807f003f003fc07fa07f413f013f92fe261cce0d8  /home/dustin/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers-small.jpg
05fe03ff07fc01d081c06080f7f4ff67efe2fe44f706c080ee08f754f704f242  /home/dustin/Downloads/GoldenEye - article-2737104-20DE666500000578-156_634x423.jpg
00021c003fff3fff07fc03fc03f807f107f703e603ed00df00ff00ff00ff00ff  /home/dustin/Downloads/GoldenEye - article-2737104-20DE66C600000578-355_634x950.jpg
7ff82fc807e003f02ff824f0036639fa19fe19fa01f001efc5fe05fe30de005c  /home/dustin/Downloads/GoldenEye - article-2737104-20DE67FF00000578-190_634x423.jpg

Now (no change):

$ python blockhash.py ~/Downloads/*.jpg
1ffc3fff00fe000021ff7e3f0f8007c03fff1f8d0f9806003ffc3ff80f0400f0  /home/dustin/Downloads/20170618_155330.jpg
1ffc3fff00fe000031ff3e3f0f8007c03fff1f8d0f9806003ffc3ff80f0400f0  /home/dustin/Downloads/20170618_155330-small.jpg
7ff00fe00ff007e00ffd07f807f003f003fc07fa07f413f017f927e261cce0d8  /home/dustin/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers.jpg
7ff00fe00fe007f00ffd07f807f003f003fc07fa07f413f013f92fe261cce0d8  /home/dustin/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers-small.jpg
05fe03ff07fc01d081c06080f7f4ff67efe2fe44f706c080ee08f754f704f242  /home/dustin/Downloads/GoldenEye - article-2737104-20DE666500000578-156_634x423.jpg
00021c003fff3fff07fc03fc03f807f107f703e603ed00df00ff00ff00ff00ff  /home/dustin/Downloads/GoldenEye - article-2737104-20DE66C600000578-355_634x950.jpg
7ff82fc807e003f02ff824f0036639fa19fe19fa01f001efc5fe05fe30de005c  /home/dustin/Downloads/GoldenEye - article-2737104-20DE67FF00000578-190_634x423.jpg
artfwo commented 6 years ago

Right, this is actually a tiny optimization.

block_bottom and block_right calculation result is identical both ways, but current implementation is a bit faster. The comment is there to explain that, but it's probably not clear enough, sorry about that.