How to layer image with transparency on top of plot

3 次查看(过去 30 天)
I have x y data that I wish to plot. I wish to compare the data to that of someone else, and the only format I have their data is in PNG format. I have removed the background from the PNG file to make it transparent, so the only opaque graphics are the data points in that PNG. I wish to plot my data UNDERNEATH the image file by taking advantage of the transparency.
The currently closest solution I've had is as in this example:
plot(0.5,0.5,'+','markersize',20); hold on
img = imshow('image.png','XData',[0 1],'YData',[0 1]);
[~, ~, alphachannel] = imread(file_diff);
set(img,'Alphadata',alphachannel);
xlabel('X[-]');
ylabel('Y[-]' );
ylim([0,1]);xlim([0 1])
But this removes my axes and seems to make all white transparent. The only transparency I want is for the image, and to place that on top of the figure. How can I do this?

回答(1 个)

Image Analyst
Image Analyst 2020-5-18
编辑:Image Analyst 2020-5-18
You might just try taking a weighted average of the two images
factor = 0.3; % Whatever...
image3 = uint8(factor * double(image1) + (1 - factor) * double(image2));
  1 个评论
Daniel Fredriksson
Daniel Fredriksson 2020-5-18
Hi. I've tried with this a bit and I can't get it to look acceptable. The ideal situation would be that cropping out the white background from the image I'm trying to layer, would effectively allow me to place just the points on my plot figure.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by