%% OVERLAYIMAGES is a simple example of displaying one image within a larger

%% load 2 images
[I1,map] = imread('trees.tif'); % small image
I2 = imread('pears.png'); % large image

%% make sure both images have the same data type
I1 = ind2rgb(I1,map);
I2 = im2double(I2);

%% overlay images

% make copy of the larger image
I3 = I2;

% create index for larger image with the size of the small image
% allow an border around the smaller image by defining 2 offsets
offsetLeft = 30;
offsetTop = 30;
irow = (1:size(I1,1)) + offsetTop; 
icol = (1:size(I1,2)) + offsetLeft;

% overlay images
I3(irow,icol,:) = I3(irow,icol,:) + I1;

% normalize maximum intensity to a value of 1 in order to prevent an
% overlight image
I3(irow,icol,:) = I3(irow,icol,:)/max(I3(:));

%% visualize result
figure
subplot(3,2,1), subimage(I1), axis off
subplot(3,2,2), subimage(I2), axis off
subplot(3,2,3:6), subimage(I3), axis off
