Reputation: 385
I have a single channel image with shape (1024,1024).
I want to overlay it with a color image of shape (1024,1024,3) using
dst = cv2.addWeighted(im, 1, newimg, 1, 0)
So First, I want to know, how can I convert newimg to 1024x1024x3...Because im
is of shape 1024x1024x3
Upvotes: 0
Views: 1458
Reputation: 1045
mask = cv2.inRange(frame, lower_blue, upper_blue)
print(mask.shape)
mask2 = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)
print(mask2.shape)
Output:
(480, 640)
(480, 640, 3)
This converts image into 3 channel.
Upvotes: 0
Reputation: 53089
This seems to be one simple solution using 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
See how to copy numpy array value into higher dimensions
Upvotes: 3