MATLAB: Linkaxes background image disappears

colormapimageslinkaxesMATLAB

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.

Best Answer

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()