Mask_all = Np.zeros ((at (), dtype= ' uint8 ') Single channel
Mask_all_enlarge = Np.zeros ((3), dtype= ' uint8 ' three channels
#为三通道图像赋值, I'm using loops here, because there's a simpler way.
Img_base = Np.zeros ((3), np.uint8)
For I in range (256):
For j in Range (256):
Img_base[i, j, 0] = np.uint8 (123.7)
Img_base[i, j, 1] = Np.uint8 (116.8)
Img_base[i, J, 2] = Np.uint8 (103.9)
#为图像的一部分赋值为另外一附图像
img_base[64:192, 104:152] = img
#两幅图像之间可以直接进行或运算:
Mask_all = Mask_all | r[' Masks ' [:,:, I]
Mask_all = Mask_all | r[' Masks ' [:,:, Person_index]
#将单通道图像依次填充到三通道图像中:
mask_all_enlarge[:,:, 0] = Mask_all
mask_all_enlarge[:,:, 1] = Mask_all
mask_all_enlarge[:,:, 2] = Mask_all
#两个三通道图像可以直接进行乘法运算:
Image_mask = Mask_all_enlarge * img_base
In addition Python uses cv2 read and write images and Skimage.io. When reading and writing images, the order of three channels is not the same, the use of the best uniform use of the same, if accidentally with a read, another write, back can also read into the write to exchange, is more trouble.
Python numpy Initializes a matrix of images