Conversion experiment 1
Image to text conversion experiment.
import os, sys
import binascii
from PIL import Image
import string
letters = set(string.letters)
im = Image.open("RotterdamHype.png").convert("RGB")
print(im.format, im.size, im.mode)
pix=im.load()
w=im.size[0]
h=im.size[1]
pict = []
pict_binary = []
for i in range(w):
for j in range(h):
a = pix[i,j]
red = a[0]
green = a[1]
blue = a[2]
pict.append(red)
pict.append(green)
pict.append(blue)
for p in pict:
pict_binary.append('{0:08b}'.format(p))
data_string = ''.join(pict_binary)
n = int(data_string, 2)
m = binascii.unhexlify('%x' % n)
free_text = ''.join(x for x in m if x in letters)
print free_text