#!/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 .to_black_white() |
im.show() |
im.save( 'assets/black_white.jpeg' ) |
def to_black_white( self ): |
''' |
Picture to black white |
''' |
im = np.asarray(Image. open ( self .path).convert( 'RGB' )) |
trans = np.array([[ 0.299 , 0.587 , 0.114 ], [ 0.299 , 0.587 , 0.114 ], [ 0.299 , 0.587 , 0.114 ]]).transpose() |
im = np.dot(im, trans) |
return Image.fromarray(np.array(im).astype( 'uint8' )) |
if __name__ = = '__main__' : |
picture().hello().run() |