git.haldean.org bitpic / master img.py
master

Tree @master (Download .tar.gz)

img.py @masterraw · history · blame

# import matplotlib.pyplot as plt
import numpy as np
import scipy.misc
import screen

def image_to_screen(imfile, brightness):
    f = scipy.misc.imread(imfile, False, "RGB")
    f = scipy.misc.imresize(f, (screen.Screen.W, screen.Screen.H))
    # plt.imshow(f)
    # plt.show()
    s = screen.Screen(f.tolist(), brightness)
    return s
    
def screen_to_image(screen, outf):
    arr = np.array(screen.colordata, dtype=np.float64)
    arr /= 255.
    arr = scipy.misc.imresize(arr, (128, 128), "nearest")
    scipy.misc.imsave(outf, arr, "png")