Python opencv(4) 调节图像亮度
2016-07-02 16:05
471 查看
将像素值变小,图像亮度减小,色彩变暗;像素值增大,图像亮度增大,色彩变亮。
运行效果图:
import cv2 import numpy as np fn = "baboon.jpg" if __name__ == '__main__': print 'loading %s ...' % fn print 'processing...' img = cv2.imread(fn) w = img.shape[1] h = img.shape[0] ii = 0 #let image get darker for xi in xrange(0,w): for xj in xrange(0,h): #set the pixel value decrease to 20% img[xj,xi,0] = int(img[xj,xi,0]*0.2) img[xj,xi,1] = int(img[xj,xi,0]*0.2) img[xj,xi,2] = int(img[xj,xi,0]*0.2) #show the process if xi%10==0 :print '.', cv2.namedWindow('img') cv2.imshow('img',img) cv2.waitKey() cv2.destroyAllWindows() print'.' print 'processing' for xi in xrange(0,w): for xj in xrange(0,h): ##set the pixel value increase to 1020% img[xj,xi,0] = int(img[xj,xi,0]*10.2) img[xj,xi,1] = int(img[xj,xi,1]*10.2) img[xj,xi,2] = int(img[xj,xi,2]*10.2) #show the process if xi%10==0 :print '.', cv2.namedWindow('img') cv2.imshow('img',img) cv2.waitKey() cv2.destroyAllWindows()
运行效果图:
相关文章推荐
- Python的爬虫程序编写框架Scrapy入门学习教程
- Selenium+Python+jenkins平台搭建和使用
- 搭建Python的Django框架环境并建立和运行第一个App的教程
- (转载)NumPy详细教程
- Python opencv(3)获取图像大小
- 测试小卒子--python--Django 测试框架
- 使用python下载图片
- Python操作sqllite3
- Python给多个变量赋值
- 测试小卒子--python--virtualenv搭建
- python图片验证码生成代码
- Python3之PrettyTable模块
- python mysql
- Python字典
- Python回顾与整理12:执行环境
- Python序列之列表
- Python数值和字符串
- Python列表之元组
- Pycharm下的Anaconda配置
- python2.x代码自动转换成python3.x