3次元配列の結合 dstack
三次元目で結合してくれる。
a.shape #((640, 480, 1))
b.shape #((640, 480, 1))
np.dstack((a, b))
# ((640, 480, 2))
opencvでBGRのBだけを取得して、他のGRを全部0で作られた画像を作成。
img = cv2.imread('363.jpg') #(640, 480, 3)
ze = np.zeros((640, 480,1))
blue = img[:,:,:1]
blue = np.dstack((blue, ze))
blue = np.dstack((blue, ze))
print(blue.shape)
print(blue[:,:,1])
cv2.imshow('blue', blue[:,:,1])
cv2.waitKey(0)
もちろん画像はめっっちゃ青