Skip to content

Instantly share code, notes, and snippets.

@acarabott
Created January 17, 2017 17:50
Show Gist options
  • Save acarabott/5030cfd7f9af5f6ccd10ded1d65cc64c to your computer and use it in GitHub Desktop.
Save acarabott/5030cfd7f9af5f6ccd10ded1d65cc64c to your computer and use it in GitHub Desktop.
Adding alpha channel to a 3 channel openCV Mat
void createAlphaImage(const cv::Mat& mat, cv::Mat_<cv::Vec4b>& dst)
{
std::vector<cv::Mat> matChannels;
cv::split(mat, matChannels);
// create alpha channel
cv::Mat alpha = matChannels.at(0) + matChannels.at(1) + matChannels.at(2);
matChannels.push_back(alpha);
cv::merge(matChannels, dst);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment