diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-11-13 19:50:06 -0500 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-11-14 00:08:27 -0500 |
commit | 9927e414d18cd27079bf827d8bf6e4eefdaa2e48 (patch) | |
tree | 57fe8216f51d5874c3954168c3e7a20b75ca294f /unshred-binary-merge-failure.py | |
parent | Initial commit. (diff) | |
download | instagram-unshredder-9927e414d18cd27079bf827d8bf6e4eefdaa2e48.tar.xz instagram-unshredder-9927e414d18cd27079bf827d8bf6e4eefdaa2e48.zip |
Slight improvement by using shift and clean up the dir structure.
Diffstat (limited to 'unshred-binary-merge-failure.py')
-rwxr-xr-x | unshred-binary-merge-failure.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/unshred-binary-merge-failure.py b/unshred-binary-merge-failure.py index abb19c5..b8dc3c8 100755 --- a/unshred-binary-merge-failure.py +++ b/unshred-binary-merge-failure.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Instagram Unshredder -- Binary Simplify Failure +# Instagram Unshredder - Binary Simplifier # by Jason A. Donenfeld <Jason@zx2c4.com> # for http://instagram-engineering.tumblr.com/post/12651721845/instagram-engineering-challenge-the-unshredder @@ -29,10 +29,14 @@ def pixel_distance(a, b): def match_score(left, right): left = left[len(left) - 1] right = right[0] - total = 0 + straight = 0 for i in xrange(0, image.size[1]): - total += pixel_distance(pixel((left + 1) * shred_width - 1, i), pixel(right * shred_width, i)) - return total + straight += pixel_distance(pixel((left + 1) * shred_width - 1, i), pixel(right * shred_width, i)) + shifted = 0 + offset = image.size[1] / 35 + for i in xrange(offset, image.size[1] - offset): + shifted += pixel_distance(pixel((left + 1) * shred_width - 1, i + offset), pixel(right * shred_width, i - offset)) + return straight / shifted def binary_simplify(order_lists): simplified = list() blacklist = list() |