Linkaxes background image disappears

Hi,
I'm looking to overlap two images, each with their own colormap. I've seen tons of answers talking about drawing them on separate axes and then linking them. However, every time I do, the 'background image' disappears. Can anyone help?
Here is my code:
hf = figure;
h1 = axes('Parent',hf);
Array = imread('background.jpg');
image(h1,Array(:,:,[1 1 1]));
[item,map] = imread('foreground.gif');
h2 = axes('Parent',hf);
image(h2,item);
linkaxes([h1 h2])
colormap(h2,map)
If you go through the code with your own image files, you'll notice that the Array image disappears as soon as I create the second axes. Although even creating the axes first and then uploading an image doesn't make a difference. What am I missing?
Thanks!
PS> It's not an animated .gif, it's just an image file, but this is how they were delivered to me.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Nov. de 2018

0 votos

The default for axes is for solid background. You would have to set the second axes background color to 'none'.
My personal recommendation for multiple images with different colormaps is to change them to RGB. You might find it convenient to use the File Exchange contribution FreezeColors . Or use mat2gray() and then im2uint8() and then ind2rgb()

1 comentario

Evelien Heyselaar
Evelien Heyselaar el 8 de Nov. de 2018
yes! thank you :) looking back, it did say this in one of the tutorials as well (well, it mentioned set(axes,'visible','off') but I thought that was just for axis labels. Clearly I have a lot left to learn about the axes options).
I tried using FreezeColors but the .gif didn't response well to being converted to RGB, so I'm going to stick with the current code just for efficiency.
Thank you again :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by