#RGB->RGBA
def rgb2rgba(img, alpha):
assert(len(img.shape) == 3)
assert(img.shape[2] == 3)
assert(len(alpha.shape) == 2)
assert(img.shape[:2] == alpha.shape)
alpha_r = np.reshape(alpha / 255.0, (alpha.shape[0], alpha.shape[1], 1))
rgba_img = np.c_[img, alpha_r * 255]
return rgba_img
参考资料
- 使用numpy为图像添加alpha通道;numpy为多维数组添加列