python实现图片变亮或者变暗的方法

yipeiwu_com6年前Python基础

本文实例讲述了python实现图片变亮或者变暗的方法。分享给大家供大家参考。具体实现方法如下:

import Image
# open an image file (.jpg or.png) you have in the working folder
im1 = Image.open("angelababy.jpg")
# multiply each pixel by 0.9 (makes the image darker)
# works best with .jpg and .png files, darker < 1.0 < lighter
# (.bmp and .gif files give goofy results)
# note that lambda is akin to a one-line function
im2 = im1.point(lambda p: p * 0.5)
# brings up the modified image in a viewer, simply saves the image as
# a bitmap to a temporary file and calls viewer associated with .bmp
# make certain you have associated an image viewer with this file type
im2.show()
# save modified image to working folder as Audi2.jpg
im2.save("angelababy2.jpg")

运行效果如下所示:

希望本文所述对大家的Python程序设计有所帮助。

相关文章

使用Python和OpenCV检测图像中的物体并将物体裁剪下来

使用Python和OpenCV检测图像中的物体并将物体裁剪下来

介绍 硕士阶段的毕设是关于昆虫图像分类的,代码写到一半,上周五导师又给我新的昆虫图片数据集了,新图片中很多图片很大,但是图片中的昆虫却很小,所以我就想着先处理一下图片,把图片中的昆虫裁剪...

python判断输入日期为第几天的实例

如下所示: # -*- coding: utf-8 -*- # 简述:要求输入某年某月某日 # 提问:求判断输入日期是当年中的第几天? def which_day(year,mont...

Python实现对文件进行单词划分并去重排序操作示例

本文实例讲述了Python实现对文件进行单词划分并去重排序操作。分享给大家供大家参考,具体如下: 文件名:test1.txt 文件内容: But soft what light thr...

python发送邮件实例分享

python发送邮件实例分享

为了更好的理解邮件发送功能的实现,要先了解邮件发送系统的大致流程。首先  电子邮件之间的相互发送接受就像  邮局邮件发送一样,从一个站点(邮件发送服务器)到目的地站点...

搞笑的程序猿:看看你是哪种Python程序员

不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同层次的Python程序员编出的Python代码,显示出了不同的风格,代码都很简单,有趣。下面让我们一起来看看一个Pyth...