MATLAB Answers

# overlay 2 imagesc, where one is a section of the larger

44 views (last 30 days)
ARP on 8 Apr 2018
Edited: Ahmet Cecen on 8 Apr 2018
Hi there,
I'm trying to overlay 2 imagesc figures into 1. Both figures have the same length in x-axis, but different y-axis. One figure is a portion of the larger (see y axis on display). They also have different colomaps, one gray and the other jet.
Figure 1 comes from a matrix of 12502x40. Figure 2 comes from a matrix of 224x140.
y axis for figure 1 has a length of 12502. y axis for figure 2 has a length of 4034.
In addition, I would like to show only the colorbar of figure 2, at the bottom of the figure.
Here are the 2 images, and what I would like to achieve (done manually with paint).   I tried with imfuse command, but could not make it work as I need.
Hope someone out there can give me a hint.
Thanks in advance.
regards
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (1)

Ahmet Cecen on 8 Apr 2018
Edited: Ahmet Cecen on 8 Apr 2018
This is kinda messy to do in MATLAB. See if you can decipher this:
%%Inputs
A = rand(100,100); %Big Image
B = 2*rand(45,32); %Small Image
BUpperLeftCorner = [20,15]; %Small Image Location
%%Make B Same Size by Padding
BB = padarray(B,BUpperLeftCorner-1,NaN,'pre');
BB = padarray(BB,size(A)-size(BB),NaN,'post');
%%Plot Overlay
figure;
% Behind Image
a1 = axes;
h1 = imagesc(a1,A); colormap(a1,'gray'); c1 = colorbar; axis image;
% Forward Image
a2 = axes;
h2 = imagesc(a2,BB); colormap(a2,'hot'); c2 = colorbar; axis image;
% Make Forward Image Transparent at Padding
alpha(h2, isfinite(BB)*1);
% Remove the Axes (the white canvas in a normal figure)
a1.Visible = 'off';
a2.Visible = 'off';
% Make background colorbar invisible.
% If you delete the colorbar, they will not align.
c1.Visible = 'off';
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!