调节图片亮度和饱和度,图片亮度饱和度,[Python]代码#
调节图片亮度和饱和度,图片亮度饱和度,[Python]代码#
[Python]代码
# conding: utf-8import sys,osimport Image,ImageEnhance#中文字符集函数def encodeChinese(msg): type = sys.getfilesystemencoding() return msg.decode('UTF-8').encode(type)#接受亮度值函数def getBrightnessValue(): print encodeChinese('请输入需要改变的亮度值:') brightnessValue = raw_input() #if True == isinstance(brightnessValue,int): try: int(brightnessValue) return brightnessValue except: getBrightnessValue()#接受饱和度值函数def getColorValue(): print encodeChinese('请输入需要改变的饱和度值:') colorValue = raw_input() #if True == isinstance(brightnessValue,int): try: int(colorValue) return colorValue except: getColorValue()#设置亮度值函数def setBrightnessValue(brightnessValue): if brightnessValue != 0: brightnessValue = 1 + 0.01*float(brightnessValue) return brightnessValue else: brightnessValue = 1 return brightnessValue#设置饱和度值函数def setColorValue(colorValue): if colorValue != 0: colorValue = 1 + 0.01*float(colorValue) return colorValue else: colorValue = 1 return colorValue#转换亮度值函数def changeBrightness(img,brightnessValue): tmp = ImageEnhance.Brightness(img) img = tmp.enhance(brightnessValue) return img#转换饱和度值函数def changeColor(img,colorValue): tmp = ImageEnhance.Brightness(img) img = tmp.enhance(colorValue) return img#打开图形文件def openImageFile(filename): try: img = Image.open(filename) except: print encodeChinese('打开文件出错,这个文件是:') print filename # img.load() return img#图片另存为函数def ImageFileSaveAs(img,targetdir,fName): try: # tg = targetdir + os.sep + 'tmp_Image' # os.mkdir(tg) img.save(targetdir + os.sep + fName) except: os.mkdir(targetdir) img.save(targetdir + os.sep + fName) #img.save(tg + os.sep + fName) print str(targetdir + os.sep + fName) + '\t' + encodeChinese('文件另存为副本完毕')def main(): print encodeChinese('请输入需要处理的贴图的路径:') rootdir = raw_input() print encodeChinese('请输入保存备份贴图的路径:') targetdir = raw_input() colorValue = getColorValue() brightnessValue = getBrightnessValue() colorValue = setColorValue(colorValue) brightnessValue = setBrightnessValue(brightnessValue) for parent,dirnames,filenames in os.walk(rootdir): for filename in filenames: print 'brightnessValue: ' + str(brightnessValue) print 'colorValue: ' + str(colorValue) fName = filename filename = parent + os.sep + fName print str(filename) img = openImageFile(filename) print str(img) ImageFileSaveAs(img,targetdir,fName) #if(img.mode =='RGB'): img = changeBrightness(img,brightnessValue) img = changeColor(img,colorValue) img.save(filename) print str(filename) print '\n'main()
相关内容
- 九九乘法表,乘法,[Python]代码im
- 从WeatherCN上提取天气数据,weathercn提取天气,# -*- codin
- Python信息录入小系统(使用shelve),pythonshelve,Python s
- python监控日志并予以清理,python监控日志,Daemonize.py
- 读取excel内容并写入sqlite中,excelsqlite,[Python]代码fn
- 扫描端口使用情况,扫描端口情况,[Python]代码#!
- subprocess 使用一例,subprocess使用,用subprocess实
- 增强亮度,,[Python]代码#
- 用途都在各个函数名称之前的注释上了,用途函数注释
- Python 读取纯真IP数据库,pythonip数据库,ip.py#!/usr/
评论关闭