'Turn a string image representation into a binary image'

def string_to_img(self, image_string):

    rows = [s for s in image_string.replace('    ', '').split('\n') if len(s)]
    height = len(rows)
    width = len(rows[0])
    im = Image.new('L', (width, height))
    for i in range(width):
        for j in range(height):
            c = rows[j][i]
            v = (c in 'X1')
            im.putpixel((i, j), v)
    return im
