How to layer image with transparency on top of plot

조회 수: 3 (최근 30일)
Daniel Fredriksson
Daniel Fredriksson 2020년 5월 18일
댓글: Daniel Fredriksson 2020년 5월 18일
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