Reputation: 33
I have extracted four channels from different color spaces and then want to combine the h,s, cb and cr channels. For this, I have converted them into a list and then appended them all one by one. Again I have converted the final list into a numpy array. But, the shape shows (4,224,224). This problem is basically append of four numpy 2D array, so that the final result will be (224,224,4) shape output.
img = cv2.imread(img_path)
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = hsv_img[:, :, 0], hsv_img[:, :, 1], hsv_img[:, :, 2]
darkYCB = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
y, cb, cr = darkYCB[:, :, 0], darkYCB[:, :, 1], darkYCB[:, :, 2]
How will I make them into 4 channel image/numpy2D_array?
Upvotes: 0
Views: 1455
Reputation: 4148
You can use np.stack(list_of_images_2d, axis=-1)
four_images = [np.random.random((100, 100)) for _ in range(4)]
stacked_images = np.stack(four_images, axis=-1)
print(stacked_images.shape)
(100, 100, 4)
Upvotes: 1