-
Notifications
You must be signed in to change notification settings - Fork 29
Organize blockhash as a module #11
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
Open
zorkian
wants to merge
1
commit into
commonsmachinery:master
Choose a base branch
from
zorkian:organize-as-module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from blockhash import blockhash, blockhash_even |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #! /usr/bin/env python | ||
| # | ||
| # Perceptual image hash calculation tool based on algorithm descibed in | ||
| # Block Mean Value Based Image Perceptual Hashing by Bian Yang, Fan Gu and Xiamu Niu | ||
| # | ||
| # Copyright 2014 Commons Machinery http://commonsmachinery.se/ | ||
| # Distributed under an MIT license, please see LICENSE in the top dir. | ||
|
|
||
| import argparse | ||
| import PIL.Image as Image | ||
|
|
||
| from blockhash import blockhash | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| parser.add_argument('--quick', type=bool, default=False, | ||
| help='Use quick hashing method. Default: False') | ||
| parser.add_argument('--bits', type=int, default=16, | ||
| help='Create hash of size N^2 bits. Default: 16') | ||
| parser.add_argument('--size', | ||
| help='Resize image to specified size before hashing, e.g. 256x256') | ||
| parser.add_argument('--interpolation', type=int, default=1, choices=[1, 2, 3, 4], | ||
| help='Interpolation method: 1 - nearest neightbor, 2 - bilinear, 3 - bicubic, 4 - antialias. Default: 1') | ||
| parser.add_argument('--debug', action='store_true', | ||
| help='Print hashes as 2D maps (for debugging)') | ||
| parser.add_argument('filenames', nargs='+') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| if args.interpolation == 1: | ||
| interpolation = Image.NEAREST | ||
| elif args.interpolation == 2: | ||
| interpolation = Image.BILINEAR | ||
| elif args.interpolation == 3: | ||
| interpolation = Image.BICUBIC | ||
| elif args.interpolation == 4: | ||
| interpolation = Image.ANTIALIAS | ||
|
|
||
| if args.quick: | ||
| method = blockhash_even | ||
| else: | ||
| method = blockhash | ||
|
|
||
| for fn in args.filenames: | ||
| im = Image.open(fn) | ||
|
|
||
| # convert indexed/grayscale images to RGB | ||
| if im.mode == '1' or im.mode == 'L' or im.mode == 'P': | ||
| im = im.convert('RGB') | ||
| elif im.mode == 'LA': | ||
| im = im.convert('RGBA') | ||
|
|
||
| if args.size: | ||
| size = args.size.split('x') | ||
| size = (int(size[0]), int(size[1])) | ||
| im = im.resize(size, interpolation) | ||
|
|
||
| hash = method(im, args.bits) | ||
|
|
||
| print('{hash} {fn}'.format(fn=fn, hash=hash)) | ||
|
|
||
| if args.debug: | ||
| bin_hash = '{:0{width}b}'.format(int(hash, 16), width=args.bits ** 2) | ||
| map = [bin_hash[i:i+args.bits] for i in range(0, len(bin_hash), args.bits)] | ||
| print("") | ||
| print("\n".join(map)) | ||
| print("") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| from distutils.core import setup | ||
| from setuptools import setup, find_packages | ||
|
|
||
| setup( | ||
| name='blockhash', | ||
| version='0.1', | ||
| version='0.1.1', | ||
| description='Perceptual image hash calculation tool', | ||
| author='Commons Machinery', | ||
| author_email='dev@commonsmachinery.se', | ||
| license='MIT', | ||
| scripts=['blockhash.py'], | ||
| requires=['pillow'], | ||
| packages=find_packages(), | ||
| entry_points={ | ||
| 'console_scripts': [ | ||
| 'blockhash=blockhash.command_line:main', | ||
| ], | ||
| }, | ||
| install_requires=['pillow'], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blockhash_even is not imported above, is this gonna work?