How to layer image with transparency on top of plot
3 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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));
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!