我有一个形状为(1024,1024)的单通道图像。

我想使用形状为(1024,1024,3)的彩色图像覆盖它dst = cv2.addWeighted(im, 1, newimg, 1, 0)
所以首先,我想知道如何将newimg转换为1024x1024x3 ...因为im的形状为1024x1024x3

最佳答案

这似乎是使用numpy的一种简单解决方案。

Create a 3-channel black image

Put your same grayscale image into each channel
newimage = np.zeros((grayimage.shape[0],grayimage.shape[1],3))
newimage[:,:,0] = grayimage
newimage[:,:,1] = grayimage
newimage[:,:,2] = grayimage

参见how to copy numpy array value into higher dimensions

10-08 12:32