How to layer image with transparency on top of plot

3 views (last 30 days)
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?

Answers (1)

Image Analyst
Image Analyst on 18 May 2020
Edited: Image Analyst on 18 May 2020
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 Comment
Daniel Fredriksson
Daniel Fredriksson on 18 May 2020
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!