Python Pillow Image Invert
作者:_John_Tian_ 时间:2023-10-02 12:33:30
本文主要是利用Python的第三方库Pillow,实现单通道灰度图像的颜色翻转功能。
# -*- encoding:utf-8 -*-
import os
import sys
from PIL import Image
from PIL import ImageOps
def img_gray_invert(img_path):
"""
invert input image.
"""
if not os.path.isfile(img_path):
print "Error for input file path."
return
image = Image.open(img_path)
image = image.convert("L")
inverted_image = ImageOps.invert(image)
return inverted_image
if __name__ == '__main__':
argv = sys.argv
if len(argv) != 3:
print """Example:
python gray_invert.py test/htc.png test/htc_inv.png
"""
else:
img_file_path = argv[1]
invert_image = img_gray_invert(img_file_path)
img_file_out = argv[2]
invert_image.save(img_file_out)
来源:https://blog.csdn.net/tianzhaixing2013/article/details/73734020
标签:python,pillow,颜色翻转
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP.NET(C#)读取Excel的文件内容
2023-07-10 22:38:35
vue绑定class与行间样式style详解
2024-05-08 10:12:12
基于Python Dash库制作酷炫的可视化大屏
2022-09-13 14:20:32
![](https://img.aspxhome.com/file/2023/5/117905_0s.jpg)
python unittest单元测试的步骤分析
2022-03-21 05:59:10
Python 编码处理-str与Unicode的区别
2021-04-15 15:38:43
JSP实现浏览器关闭cookies情况下的会话管理
2024-03-27 07:29:10
sql查询语句之平均分、最高最低分及排序语句
2024-01-19 06:43:34
![](https://img.aspxhome.com/file/2023/0/116800_0s.png)
python GUI库图形界面开发之PyQt5动态加载QSS样式文件
2022-09-16 19:50:02
![](https://img.aspxhome.com/file/2023/5/118585_0s.png)
Python os库常用操作代码汇总
2021-04-17 04:07:51
python中对_init_的理解及实例解析
2023-03-15 11:08:23
![](https://img.aspxhome.com/file/2023/2/81632_0s.png)
python pexpect ssh 远程登录服务器的方法
2021-07-10 22:28:53
![](https://img.aspxhome.com/file/2023/9/134729_0s.jpg)
python __add__()的具体使用
2022-11-29 07:49:22
![](https://img.aspxhome.com/file/2023/3/97673_0s.png)
嵌入式Web视频点播系统实现方法
2007-10-10 21:17:00
python机器学习GCN图卷积神经网络原理解析
2022-09-29 06:36:14
![](https://img.aspxhome.com/file/2023/4/99614_0s.png)
Python高级编程之消息队列(Queue)与进程池(Pool)实例详解
2021-12-14 17:30:24
![](https://img.aspxhome.com/file/2023/6/107496_0s.png)
php获取文件大小的方法
2024-05-13 09:26:15
如何用python多次调用exe文件运行不同的结果
2023-07-08 03:01:24
Python入门教程(九)Python字符串介绍
2023-02-05 22:34:43
![](https://img.aspxhome.com/file/2023/8/80488_0s.png)
MySQL5.7 windows二进制安装教程
2024-01-24 04:10:01
浅谈Python中函数的定义及其调用方法
2022-09-01 09:35:35
![](https://img.aspxhome.com/file/2023/0/134720_0s.jpg)