[python]代码库
#!/usr/bin/env python
# encoding: utf-8
import numpy as np
from PIL import Image
class picture:
def __init__(self):
self.path = 'assets/picture.jpeg'
def hello(self):
'''
This is a welcome speech
:return: self
'''
return self
def run(self):
'''
The program entry
'''
im = self.old_film()
im.show()
im.save('assets/old_film.jpeg')
def old_film(self):
'''
Picture to old film
'''
im = np.asarray(Image.open(self.path).convert('RGB'))
trans = np.array([[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]).transpose()
im = np.dot(im, trans).clip(max=255)
return Image.fromarray(np.array(im).astype('uint8'))
if __name__ == '__main__':
picture().hello().run()
[代码运行效果截图]