from PIL import Image

image = Image.open("portrait.png")

width, height = image.size

image_rgb = image.convert("RGB")

for x in range(width):
    for y in range(height):
        r,g,b = image_rgb.getpixel((x,y))
        int("{:08b}".format(r)[::-1], 2)
        r = int("{:08b}".format(r)[::-1], 2)
        g = int("{:08b}".format(g)[::-1], 2)
        b = int("{:08b}".format(b)[::-1], 2)
        image_rgb.putpixel((x, y), (r, g, b))

image_rgb.save("portrait_decoded.png", "png")

