1.使用opencv
b_channel, g_channel, r_channel = cv2.split(img)
alpha_channel = np.ones(b_channel.shape, dtype=b_channel.dtype) * 50 #creating a dummy alpha channel image.
img_BGRA = cv2.merge((b_channel, g_channel, r_channel, alpha_channel))
2.使用PIL
from PIL import Image
img = Image.open("path")
image = img.convert("RGBA") # 将img转换成RGBA格式
image = img.convert("RGB") # 将img转换成RGB格式
image = img.convert("L") # 将img转换成灰度图