Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Below my implementation

void join(cv::Mat& image1, const cv::Mat& image2)
{
    assert(image1.rows == image2.rows);
    assert(image1.cols == image2.cols);

    std::vector<cv::Mat> channels;
    std::vector<cv::Mat> channels2;
    cv::split(image1, channels);
    cv::split(image2, channels2);

    cv::Mat c1 = (255.0 - channels2[3]) / 255.0;
    cv::Mat c2 = channels2[3] / 255.0;
    for (size_t i = 0; i < 3; i++)
    {
        channels[i] = channels[i].mul(c1) + channels2[i].mul(c2);
    }
    cv::merge(channels, image1);
}