What is the best way to convert RGB image to RGBA in python using opencv?
Let's say I have one array with shape
(185, 198, 3) - it is RGB
and the other is alpha mask with shape (185, 198)
How to merge them and save to file?
What is the best way to convert RGB image to RGBA in python using opencv?
Let's say I have one array with shape
(185, 198, 3) - it is RGB
and the other is alpha mask with shape (185, 198)
How to merge them and save to file?
Here is an another simple example using Grabcut, it helps to get the right order of channels when saving the image on disk vs
pyplot
.With opencv3, this should work:
Python
C++
You may use
cv2.merge()
to add the alpha channel to the given RGB image, but first you need to split the RGB image toR, G and B
channels, as per the documentation:And this can be done as: