这里有一张图片:
改变像素值,生成日落的效果。
import cv2
import numpy as np
fn = "cat.jpg"
if __name__ == '__main__':
print 'loading %s ...' % fn
print 'processing ...',
img = cv2.imread(fn)
w = img.shape[1]
h = img.shape[0]
ii = 0
#make a sunset effect
for xi in xrange(0,w):
for xj in xrange(0,h):
img[xj,xi,0] = int(img[xj,xi,0]*0.7)#set blue value decrease by 70%
img[xj,xi,0] = int(img[xj,xi,1]*0.7)#set green value decrease by 70%
if xi%10 == 0 :print'.',
cv2.namedWindow('img')
cv2.imshow('img',img)
cv2.waitKey()
cv2.destroyAllWindows()
和原图区别不大,要是图中蓝色和绿色成分较多的话,效果就会很明显了。