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

yipeiwu_com5年前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列表元素常见操作简单示例

本文实例讲述了Python列表元素常见操作。分享给大家供大家参考,具体如下: 列表类似于java中的数组,用方括号表示,逗号分隔其中的元素 #赋值、打印 children_names...

Tensorflow 同时载入多个模型的实例讲解

有时我们希望在一个python的文件空间同时载入多个模型,例如 我们建立了10个CNN模型,然后我们又写了一个预测类Predict,这个类会从已经保存好的模型restore恢复相应的图结...

python实现切割url得到域名、协议、主机名等各个字段的例子

有一个需求就是需要对url进行进一步的划分得到详细的各个字段信息,下面是简单的实现: #!/usr/bin/python # -*- coding: UTF-8 -*- ''' __...

使用Python操作MySQL的一些基本方法

前奏 为了能操作数据库, 首先我们要有一个数据库, 所以要首先安装Mysql, 然后创建一个测试数据库python_test用以后面的测试使用 CREATE DATABASE `py...

pytorch之ImageFolder使用详解

pytorch之ImageFolder使用详解

pytorch之ImageFolder torchvision已经预先实现了常用的Dataset,包括前面使用过的CIFAR-10,以及ImageNet、COCO、MNIST、LSUN等...