Python Pillow Image Invert
本文主要是利用Python的第三方庫Pillow,實(shí)現(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)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
python中Apriori算法實(shí)現(xiàn)講解
給大家詳細(xì)講解一下Apriori 算法在python中的實(shí)現(xiàn)過程,有需要的朋友收藏一下本片文章吧。2017-12-12
Python自動(dòng)化運(yùn)維中服務(wù)器性能監(jiān)控與告警詳解
這篇文章主要為大家詳細(xì)介紹了Python自動(dòng)化運(yùn)維中服務(wù)器性能監(jiān)控與告警的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2025-04-04
Python通過Socket手動(dòng)實(shí)現(xiàn)HTTP協(xié)議
這篇文章主要為大家詳細(xì)介紹了Python如何通過Socket手動(dòng)實(shí)現(xiàn)HTTP協(xié)議,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一2024-03-03
Python利用matplotlib實(shí)現(xiàn)繪制密度散點(diǎn)圖
這篇文章主要介紹了如何基于Python語言的matplotlib模塊,對(duì)Excel表格文件中的指定數(shù)據(jù)加以密度散點(diǎn)圖繪制的方法,有需要的小伙伴可以參考下2024-04-04
Python實(shí)現(xiàn)i人事自動(dòng)打卡的示例代碼
這篇文章主要介紹了Python實(shí)現(xiàn)i人事自動(dòng)打卡的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
python PyQt5/Pyside2 按鈕右擊菜單實(shí)例代碼
本文通過實(shí)例代碼給大家介紹了python PyQt5/Pyside2 按鈕右擊菜單,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-08-08
使用Python腳本將絕對(duì)url替換為相對(duì)url的教程
這篇文章主要介紹了使用Python腳本將絕對(duì)url替換為相對(duì)url的教程,腳本代碼非常簡單,需要的朋友可以參考下2015-04-04
合并百度影音的離線數(shù)據(jù)( with python 2.3)
這篇文章主要介紹了合并百度影音的離線數(shù)據(jù)( with python 2.3)的相關(guān)資料2015-08-08

