data/dtype/size/shape/len
‘’’
import cv2 as cv
import numpy as np
def access_pixes(image):
print(image.shape)
height = image.shape[0]
width = image.shape[1]
channels = image.shape[2]
print(“width : %s, height : %s, channels : %s”%(width, height, channels))
for row in range(height):
for col in range(width):
for c in range(channels):
pv = image[row, col, c]
image[row, col, c] = 255-pv #像素取反
cv.imshow(“pixels_demo”, image)
def create_image():
#多通道修改
‘’’
img = np.zeros([512, 512, 3], np.uint8) #定义一个三维都是0的矩阵
img[:, :, 0] = np.ones([512, 512])*255 #修改第一个通道(blue通道)
cv.imshow(“new image”, img)
#单通道修改
img = np.ones([512, 512, 1], np.uint8) #定义一个一维的单通道矩阵
img = img*127
cv.imshow("new image", img)
'''
m1 = np.ones([3, 3], np.uint8)
m1.fill(122.83)
print(m1)
m2 = m1.reshape([1, 9])
print(m2)
def inverse(image):
dst = cv.bitwise_not(image) #像素取反
cv.imshow(“inverse demo”, dst)
print("----------Hello python-------------")
src = cv.imread(“E:/image/lena.jpg”)
cv.namedWindow(“input_image”, cv.WINDOW_AUTOSIZE)
cv.imshow(“input_image”, src) #显示图片,命名为input_image
t1 = cv.getTickCount()
inverse(src)
t2 = cv.getTickCount()
time = (t2-t1)/cv.getTickCount()
print(“time : %s ms”%(time*1000))
cv.waitKey(0)
cv.destroyAllWindows()