如何查看图片某一位置的像素值以及改变其值

import cv2
root = '/root/group-dia/zxb/test.jpg'
img = cv2.imread(root)
print img.item(10, 10, 0)
print img.item(10, 10, 1)
print img.item(10, 10, 2)

img.itemset((10, 10, 0), 0)
img.itemset((10, 10, 0), 0)
img.itemset((10, 10, 0), 0)

print img.item(10, 10, 0) # R
print img.item(10, 10, 1) # G
print img.item(10, 10, 2) # B

把图片的所有像素值都设置为同一个值:

from matplotlib import pyplot as plt
import pylab
img[:,:,:] = [250, 230, 201]
print img[12, 12] # 查看point(12,12)的像素值
plt.imshow(img, 'img')
pylab.show()


你可能感兴趣的:(PyTorch)