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.

 採用された回答

Walter Roberson
Walter Roberson 2018 年 11 月 7 日

0 投票

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 件のコメント

Evelien Heyselaar
Evelien Heyselaar 2018 年 11 月 8 日
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 :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeColor and Styling についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by