python怎么实现图片特效处理
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要介绍了python怎么实现图片特效处理的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇python怎么实现图片特效处理文章都会有所收获,下面我们一起来看看吧。前
千家信息网最后更新 2026年11月01日python怎么实现图片特效处理
这篇文章主要介绍了python怎么实现图片特效处理的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇python怎么实现图片特效处理文章都会有所收获,下面我们一起来看看吧。
前言:
对于 图片处理,在日常生活中我们常常能够看到。
比如发个朋友圈之前,我们需要给自己的照片加个滤镜;在上传头像时候,需要对照片进行裁剪,这些都是图片的处理。
待处理的原图:
一、黑白特效
将图片处理后,变为黑白颜色
把像素的R,G,B三个通道数值都置为:
r*0.299+g*0.587+b*0.114效果
黑白特效:
代码:
#!/usr/bin/env python# encoding: utf-8import numpy as npfrom PIL import Imageclass picture:'''This is a main Class, the file contains all documents.One document contains paragraphs that have several sentencesIt loads the original file and converts the original file to new contentThen the new content will be saved by this class'''def __init__(self):self.path = 'assets/picture.jpeg'def hello(self):'''This is a welcome speech:return: self'''print('*' * 50)print(' ' * 20 + '图片转换特效之黑白')print(' ' * 5 + '作者: autofelix Date: 2022-01-17 13:14')print('*' * 50)return selfdef 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()二、流年特效
将图片处理后,变为流年特效
把R通道的数值开平方,然后乘以一个参数
效果
流年特效:
代码:
#!/usr/bin/env python# encoding: utf-8import numpy as npfrom PIL import Imageclass picture:'''This is a main Class, the file contains all documents.One document contains paragraphs that have several sentencesIt loads the original file and converts the original file to new contentThen the new content will be saved by this class'''def __init__(self):self.path = 'assets/picture.jpeg'def hello(self):'''This is a welcome speech:return: self'''print('*' * 50)print(' ' * 20 + '图片转换特效之流年')print(' ' * 5 + '作者: autofelix Date: 2022-01-17 13:14')print('*' * 50)return selfdef 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]) * paramsim2 = im * [0.0, 1.0, 1.0]im = im1 + im2return Image.fromarray(np.array(im).astype('uint8'))if __name__ == '__main__':picture().hello().run()三、旧电影特效
将图片处理后,变为旧电影特效
把像素的R,G,B三个通道数值,3个通道的分别乘以3个参数后求和,最后把超过255的值置为255
效果
旧电影特效:
代码:
#!/usr/bin/env python# encoding: utf-8import numpy as npfrom PIL import Imageclass picture:'''This is a main Class, the file contains all documents.One document contains paragraphs that have several sentencesIt loads the original file and converts the original file to new contentThen the new content will be saved by this class'''def __init__(self):self.path = 'assets/picture.jpeg'def hello(self):'''This is a welcome speech:return: self'''print('*' * 50)print(' ' * 20 + '图片转换特效之旧电影')print(' ' * 5 + '作者: autofelix Date: 2022-01-17 13:14')print('*' * 50)return selfdef 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()四、反色特效
将图片处理后,变为反色特效
这个最简单了,用255减去每个通道的原来的数值
效果
反色特效:
代码:
#!/usr/bin/env python# encoding: utf-8import numpy as npfrom PIL import Imageclass picture:'''This is a main Class, the file contains all documents.One document contains paragraphs that have several sentencesIt loads the original file and converts the original file to new contentThen the new content will be saved by this class'''def __init__(self):self.path = 'assets/picture.jpeg'def hello(self):'''This is a welcome speech:return: self'''print('*' * 50)print(' ' * 20 + '图片转换特效之反色')print(' ' * 5 + '作者: autofelix Date: 2022-01-17 13:14')print('*' * 50)return selfdef run(self):'''The program entry'''im = self.reverse()im.show()im.save('assets/reverse.jpeg')def reverse(self):'''Picture to reverse'''im = 255 - np.asarray(Image.open(self.path).convert('RGB'))return Image.fromarray(np.array(im).astype('uint8'))if __name__ == '__main__':picture().hello().run()关于"python怎么实现图片特效处理"这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对"python怎么实现图片特效处理"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。
特效
图片
处理
通道
代码
作者
效果
数值
流年
电影
黑白
知识
三个
像素
内容
参数
照片
篇文章
价值
前言
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
手冲咖啡和咖啡机区别
中关村互联网科技集团
重生之互联网科技帝国
互联网科技保险
互联网最新的科技
北京互联网科技
碳银互联网科技
天下捷融互联网科技
齐家互联网科技有限公司
深圳互联网科技怎么样
金融科技与互联网金融相同和不同
厦门比较好的科技互联网公司
崇明区互联网教育科技诚信经营
燊美集互联网科技有限公司
高科技互联网发展前景如何
互联网安防科技感
广州互联网高科技取餐柜
互联网科技手抄报图片
株洲百竞科技的互联网营销顾问
互联网 科技节活动 微视频大赛
科技企业和互联网企业
互联网 的科技创新
掌上梦互联网科技
佩信高科技互联网
呼和浩特新华互联网科技学院
深圳育鹏互联网科技有限公司招聘
威龙国际互联网科技公司
卓翼科技产业互联网合作
科技互联网的核心竞争力
风投北京互联网科技