Conversion experiment 1: Difference between revisions
(Created page with "Image to text conversion experiment. <br /> <source lang="python"> import os, sys import binascii from PIL import Image import string letters = set(string.letters) im = Imag...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Image to text conversion experiment. <br /> | Image to text conversion experiment. <br /> | ||
The Script converts RGB values of each pixel of the image to its binary representation and maps each digit combination with the letter. All non-alphabetic signs, numbers and white spaces are deleted from the final output. | |||
<source lang="python"> | <source lang="python"> | ||
import os, sys | import os, sys | ||
Line 8: | Line 10: | ||
letters = set(string.letters) | letters = set(string.letters) | ||
im = Image.open(" | im = Image.open("molevich.png").convert("RGB") | ||
print(im.format, im.size, im.mode) | print(im.format, im.size, im.mode) | ||
pix=im.load() | pix=im.load() |
Latest revision as of 18:32, 12 January 2016
Image to text conversion experiment.
The Script converts RGB values of each pixel of the image to its binary representation and maps each digit combination with the letter. All non-alphabetic signs, numbers and white spaces are deleted from the final output.
import os, sys
import binascii
from PIL import Image
import string
letters = set(string.letters)
im = Image.open("molevich.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