2

I am trying to display 2 overlaid images in an app within a UIAxes. I know about imshowpair(bg,fg,'blend'), and although it does work, it doesn't allow me to control the transparency level.

I tried following Steve's tip, where he recommends using:

f1 = imshow(fig1); 
f2 = imshow(fig2);
set(f2,'AlphaData',alpha) 

but it doesn't work properly within a UIAxes. When I set the 'AlphaData' property, both images become transparent.

How can I do this? The idea would be to have a slider where the user can set the transparency of the top image interactively.

Reference code and images

f1 = imshow(ref,'Parent',app.UIAxes);
hold on
f2 = imshow(gbT2,'Parent',app.UIAxes);
hold off
set(f2,'AlphaData', alpha);

How it looks in a figure vs how it looks in UIAxes:

figure vs UIAxes

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
  • 1
    Blending images is often just a weighted sum of the two images. If they are the same size and are `uint8` type then you could just do `figBlend = uint8(alpha*fig1 + (1-alpha)*fig2)` where `alpha` is a number between 0 and 1 that controls the amount of blending. – jodag Aug 26 '18 at 17:58
  • I am not sure they are uint8, I imported from tiff with `imread(img)`. What if they are not the same size (they are not)? I could crop them, but would prefer another solution. – Renato Bichara Vieira Aug 27 '18 at 18:03

1 Answers1

1

Running in R2018a, I'm not able to reproduce this. This is the code I used though:

I = imread('cameraman.tif');
f1 = imshow(I,'Parent',app.UIAxes);
hold(app.UIAxes, 'on')

I2 = imread('pout.tif');
f2 = imshow(I2,'Parent',app.UIAxes);
hold(app.UIAxes, 'off')

set(f2,'AlphaData', 0.5);