-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.py
84 lines (65 loc) · 2.04 KB
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os, sys
from PIL import Image
#test_image = Image.open('data/test_image.jpg')
#print 'Image Mode: %s' % test_image.mode
#print 'Width: %s px, Height: %s px' % (test_image.size[0], test_image.size[1])
#width, height = test_image.size
#pixels = list(test_image.getdata())
#for col in xrange(width):
# print pixels[col:col+width]
orig_image = Image.open('data/cat_grumpy.png')
grayscale = orig_image.convert('LA')
grayscale.save('data/grayscale_orig.png')
size = 9, 8
im = Image.open('data/grayscale_orig.png')
im2 = im.resize((size[0], size[1]), Image.ANTIALIAS)
im2.save('data/thumb_orig.png')
orig_image = Image.open('data/cat_grumpy_modif.png')
grayscale = orig_image.convert('LA')
grayscale.save('data/grayscale_modif.png')
im = Image.open('data/grayscale_modif.png')
#im.thumbnail(size, Image.ANTIALIAS)
im2 = im.resize((size[0], size[1]), Image.ANTIALIAS)
im2.save('data/thumb_modif.png')
orig_thumb = Image.open('data/thumb_orig.png')
width, height = orig_thumb.size
pixels = list(orig_thumb.getdata())
print width
print height
diff = []
for row in xrange(height):
for col in xrange(width):
if col != width:
diff.append(pixels[col+row] > pixels[(col+row)+1])
for col in xrange(width - 1):
print diff[col:col+(width-1)]
modif_thumb = Image.open('data/thumb_modif.png')
width, height = modif_thumb.size
pixels = list(modif_thumb.getdata())
print width
print height
diff2 = []
for row in xrange(height):
for col in xrange(width):
if col != width:
diff2.append(pixels[col+row] > pixels[(col+row)+1])
for col in xrange(width - 1):
print diff2[col:col+(width-1)]
#convert the binary array to a hexa string
# a true value will have have a binary value of 1, and a false value will have one of 0
def hash_f(diff):
decimal = 0
hex_string = []
for index, value in enumerate(diff):
if value:
decimal += 2**(index % 8)
if (index % 8) == 7:
hex_string.append(hex(decimal)[2:].rjust(2, '0'))
decimal = 0
ret_val = ''.join(hex_string)
return ret_val
orig = hash_f(diff)
modif = hash_f(diff2)
print orig
print modif
print orig == modif