這篇文章主要介紹了Python圖像的增強處理操作,結合實例形式分析了使用ImageEnhance類處理圖片的亮度、對比度、色度以及銳度等相關操作技巧,需要的朋友可以參考下
本文實例講述了Python圖像的增強處理操作。分享給大家供大家參考,具體如下:
python中PIL模塊中有一個叫做ImageEnhance的類,該類專門用於圖像的增強處理,不僅可以增強(或減弱)圖像的亮度、對比度、色度,還可以用於增強圖像的銳度。
具體見下面的例子:
#-*- coding: UTF-8 -*- from PIL import Image from PIL import ImageEnhance #原始圖像 image = Image.open('lena.jpg') image.show() #亮度增強 enh_bri = ImageEnhance.Brightness(image) brightness = 1.5 image_brightened = enh_bri.enhance(brightness) image_brightened.show() #色度增強 enh_col = ImageEnhance.Color(image) color = 1.5 image_colored = enh_col.enhance(color) image_colored.show() #對比度增強 enh_con = ImageEnhance.Contrast(image) contrast = 1.5 image_contrasted = enh_con.enhance(contrast) image_contrasted.show() #銳度增強 enh_sha = ImageEnhance.Sharpness(image) sharpness = 3.0 image_sharped = enh_sha.enhance(sharpness) image_sharped.show()
結果如下:
原始圖像
亮度增強
色度增強
對比度增強
銳度增強
更多關於Python相關內容可查看本站專題:《Python數學運算技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧彙總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。