# -*- coding: utf-8 -*-标签:color,image,cv2,像素,openCV,amount,图像,np,height From: https://blog.51cto.com/u_12504263/5718745
import cv2, matplotlib
import numpy as np
import matplotlib.pyplot as plt
cols = 640
rows = 480
image = cv2.imread('2.jpg')
print image.shape
width = image.shape[0]
height = image.shape[1]
print width
print height
amount = 2.0
print 'orginal_image=',image
print 'image[0,1]=',image[0,1]
#表示图片像素image[起始位置,步长]
for x in range(0,width):
for y in range(0,height):
pixel = image[x,y]
b = pixel[0]
g = pixel[1]
r = pixel[2]
if x < width/2 and y < height/2:
color = np.array([b,g,r*amount],np.uint8)
elif x > width/2 and y < height/2:
color = np.array([b,g*amount,r],np.uint8)
elif x < width/2 and y > height/2:
color = np.array([b*amount,g,r],np.uint8)
else:
color = np.array([b*amount,g*amount,r*amount],np.uint8)
image[x,y] = color
print 'new_image=',image
# image[x,y] = color
# image[0:150,0:110] = [0, 255, 128]
cv2.imshow('image',image)
cv2.imwrite('access_pixel.png',image)
cv2.waitKey(0)