Use alpha transparency to overlay images in App designer

6 views (last 30 days)
Hi all,
I'm creating an app using app designer with Matlab R2022a. I have an axis (app.axisimage) and two images (app.im and GT_RGB).
I am trying to overlay both images in the axis, giving some transparency to the one on top (I guess the second one displayed). The transparency is controlled with the value of a slider (app.TransparencySlider).
I have tried several methods but non of them work.
My last tried piece of code si this:
imshow(app.im,'Parent',app.axisimage);
hold(app.axisimage,'on')
him = imshow(GT_RGB,'Parent',app.axisimage);
him.AlphaData = app.TransparencySlider.Value;
hold(app.axisimage,'off')
This shows the second image (GT_RGB) with the desired transparency, but the first image is not under it. Just in case it is important, both images are in single format with values ranging from 0 to 1.
Any clue of how could I do that? Thanks in advance for your help.
  1 Comment
Miguel Ángel
Miguel Ángel on 20 Oct 2022
As an update. I've seen the 'NexPlot property of the axes so I have also tried the following but it also does not work:
cla(app.axisimage)
app.axisimage.NextPlot = 'Add';
imshow(app.im,'Parent',app.axisimage);
him = imshow(GT_RGB,'Parent',app.axisimage);
him.AlphaData = app.TransparencySlider.Value;
app.axisimage.NextPlot = 'Replace';
Thanks!

Sign in to comment.

Answers (1)

Miguel Ángel
Miguel Ángel on 20 Oct 2022
I finally solved it myself like this:
imshow(app.im,'Parent',app.axisimage);
app.axisimage.NextPlot = 'Add';
him = imshow(GT_RGB,'Parent',app.axisimage);
him.AlphaData = app.TransparencySlider.Value;
app.axisimage.NextPlot = 'Replace';
No need to cla(app.axisimage)
Thanks!

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!