Python Pillow Image Invert
更新時間:2019年01月22日 09:44:55 作者:_John_Tian_
今天小編就為大家分享一篇關(guān)于Python Pillow Image Invert,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
本文主要是利用Python的第三方庫Pillow,實現(xiàn)單通道灰度圖像的顏色翻轉(zhuǎn)功能。
# -*- 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)
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
Python自動化運維中服務(wù)器性能監(jiān)控與告警詳解
這篇文章主要為大家詳細介紹了Python自動化運維中服務(wù)器性能監(jiān)控與告警的相關(guān)知識,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下2025-04-04
Python通過Socket手動實現(xiàn)HTTP協(xié)議
這篇文章主要為大家詳細介紹了Python如何通過Socket手動實現(xiàn)HTTP協(xié)議,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一2024-03-03
Python利用matplotlib實現(xiàn)繪制密度散點圖
這篇文章主要介紹了如何基于Python語言的matplotlib模塊,對Excel表格文件中的指定數(shù)據(jù)加以密度散點圖繪制的方法,有需要的小伙伴可以參考下2024-04-04
python PyQt5/Pyside2 按鈕右擊菜單實例代碼
本文通過實例代碼給大家介紹了python PyQt5/Pyside2 按鈕右擊菜單,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2019-08-08
合并百度影音的離線數(shù)據(jù)( with python 2.3)
這篇文章主要介紹了合并百度影音的離線數(shù)據(jù)( with python 2.3)的相關(guān)資料2015-08-08

