Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

How can I get the result I wish? Thanks a lot!

How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

This is my test code:

void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));

cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);

}

How can I get the result I wish? Thanks a lot!

How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

This is my test code:

void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));

cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);

}

And this is the original image files: C:\fakepath\overlay.png C:\fakepath\underlay.png

How can I get the result I wish? Thanks a lot!

How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

This is my test code:

void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));

cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);
underlay);  }

}

And this is the original image files: C:\fakepath\overlay.pngoverlay.png C:\fakepath\underlay.pngunderlay.png

How can I get the result I wish? Thanks a lot!

How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

This is my test code:

void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));

cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);  }

And this is the original image files: overlay.png underlay.png

How can I get the result I wish? Thanks a lot!

How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

This is my test code:

void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));

cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);  }

And this is the original image files: overlay.png underlay.png

How can I get the result I wish? Thanks a lot!