python 将彩色图片 黑白图片变换
程序员文章站
2022-05-21 23:54:01
...
效果
代码
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 31 20:46:44 2020
@author: JZJ
"""
from PIL import Image
import numpy as np
im = np.array(Image.open("C:/Pictures/Camera Roll/ex.jpg").convert('L'))
# 图像为二维数组
d = 255 * (im/255)**2 # 像素的平方
myim = Image.fromarray(d.astype('uint8'))
myim.save("C:/Pictures/Camera Roll/ex2.jpg")
上一篇: Redis集群