[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.fleeting()
im.show()
im.save('assets/fleeting.jpeg')
def fleeting(self, params=12):
'''
Picture to fleeting
'''
im = np.asarray(Image.open(self.path).convert('RGB'))
im1 = np.sqrt(im * [1.0, 0.0, 0.0]) * params
im2 = im * [0.0, 1.0, 1.0]
im = im1 + im2
return Image.fromarray(np.array(im).astype('uint8'))
if __name__ == '__main__':
picture().hello().run()
[代码运行效果截图]