# First create the image with alpha channel
rgba = cv2.cvtColor(rgb_data, cv2.COLOR_RGB2RGBA)
# Then assign the mask to the last channel of the image
rgba[:, :, 3] = alpha_data
C++ +<
# First create the image with alpha channel
cv::cvtColor(rgb_data, rgba , cv::COLOR_RGB2RGBA);
# Split the image for access to alpha channel
std::vector<cv::Mat>channels(4);
cv::split(rgba, channels);
# Assign the mask to the last channel of the image
channels[3] = alpha_data;
# Finally concat channels for rgba image
cv::merge(channels, 4, rgba);
下面是另一个使用Grabcut的简单示例,它有助于在将图像保存到磁盘vs
pyplot
时获得正确的通道顺序。使用opencv3,应该可以:
Python
C++ +<
可以使用^{} 将alpha通道添加到给定的RGB图像,但首先需要按照documentation将RGB图像分割到
R, G and B
通道:可以这样做:
相关问题 更多 >
编程相关推荐