As always, "overlay" can mean a number of things. For the purposes described, I'm assuming that this is a basic image blending/composition task, so doing figure capture is undesirable. Since the parent and inset images are not known, I'm going to use a simple example. The inset image object content is not binarized and contains soft edges. The object content is presented both as positive (bright on dark) and negative (dark on light) against black, white, and 50% gray.
First, let's start with some operations using basic MATLAB/IPT tools.
A = imread('peppers.png');
a = imread('insetlogo.png');
aaa = repmat(im2uint8(a),[1 1 3]);
B(end-sza(1)+1:end,end-sza(2)+1:end,:) = aaa;
Direct insertion is simple, but it's rarely what's intended when someone says "overlay". Often they just want to change the opacity of the image. Sometimes that works, sometimes the sparsity of the object content makes the overlay's background stick out like a sore thumb:
aaa = repmat(im2uint8(a),[1 1 3]);
Croi = C(end-sza(1)+1:end,end-sza(2)+1:end,:);
C(end-sza(1)+1:end,end-sza(2)+1:end,:) = aaa*alph + Croi*(1-alph);
By leveraging the neutral response characteristics of simple arithmetic, we can blend the two images independent of their opacity. An addition blend works great for the white-on-black example:
aaa = repmat(im2uint8(a),[1 1 3]);
Droi = D(end-sza(1)+1:end,end-sza(2)+1:end,:);
D(end-sza(1)+1:end,end-sza(2)+1:end,:) = blended;
Similarly, a multiply blend works good for the black-on-white example:
aaa = repmat(im2uint8(a),[1 1 3]);
Eroi = E(end-sza(1)+1:end,end-sza(2)+1:end,:);
blended = im2uint8(im2double(aaa) .* im2double(Eroi));
E(end-sza(1)+1:end,end-sza(2)+1:end,:) = blended;
Of course, blending can be combined with scalar alpha compositing, though it has its limitations.
aaa = repmat(im2uint8(a),[1 1 3]);
Froi = F(end-sza(1)+1:end,end-sza(2)+1:end,:);
blended = im2uint8(im2double(aaa) .* im2double(Froi));
F(end-sza(1)+1:end,end-sza(2)+1:end,:) = blended*alph + Froi*(1-alph);
Notice how this is getting progressively more complicated and how everything is going to be dependent on the class and depth of the input images? What about nonscalar alpha? What if I want to overlay a transparent PNG? What if the base image is transparent too? Nothing in base MATLAB or IPT know what to do with an RGBA image, let alone how to handle compositing two.
The answer is usually simple. Stop doing it the hard way. Not everything has to be done in MATLAB. Image manipulation software like GIMP or Photoshop exist because they're suited for their tasks. This whole affair is usually going to be simpler to accomplish outside of MATLAB.
That said, maybe you want automation or integration into a larger MATLAB workflow. There are image blending tools on the File Exchange. MIMT imblend() can do any kind of blending or composition between any two images of the same height and width. They don't need to have the same number of channels or be of the same class (so long as they're scaled correctly for their class). One or both images can have alpha content. A = imread('peppers.png');
a = imread('insetlogo.png');
Broi = B(end-sza(1)+1:end,end-sza(2)+1:end,:);
blended = imblend(a,Broi,1,'grainmerge',0.5);
B(end-sza(1)+1:end,end-sza(2)+1:end,:) = blended;
Note again that the neutral response characteristics of basic blending alone can implicitly mask off parts of the foreground image. As before, addition (lineardodge) is neutral when FG = 0. Multiplication is neutral when the FG = 1. The complements have the opposite behavior. Symmetric modes like 'linearlight' have a neutral response when FG = 0.5, so the gray part of the image appears transparent -- all without the need for an alpha map.
If your logo is a transparent PNG, just read the image and alpha with imread(), concatenate them with cat() to form an RGBA image, and use imblend() like any other image. Use MIMT splitalpha() or basic indexing to split or discard the alpha in the resulting image. Processing IA/RGBA inputs is really no different than processing I/RGB inputs, except the need to make sure that the IA/RGBA images aren't fed into any MATLAB/IPT tools that can't handle them directly (imwrite, imshow)
A = imread('peppers.png');
[a,~,aalph] = imread('insetlogotrans.png');
Broi = B(end-sza(1)+1:end,end-sza(2)+1:end,:);
blended = imblend(a,Broi,1,'normal');
[blended,~] = splitalpha(blended);
B(end-sza(1)+1:end,end-sza(2)+1:end,:) = blended;
The links for MIMT and the imblend() webdocs are above. Further documentation including neutral response descriptions can be found in this PDF. If you don't want to use imblend(), you can always open it up and figure out how to make your own code do what imblend() does.
EDIT: I'll point this out since OP mentioned it. With only a few exceptions unrelated to this topic, nothing in MIMT requires Image Processing Toolbox.
Other basic composition questions:
basic image composition (logical/multiplicative, no MIMT)
apply a soft-edged circular mask (strictly MIMT (only replacepixels() is really used))
combine masks with image in different ways (colored ROI indicators on medical diagrams/images)
instagram logo overlay (non-MIMT logical/multiplicative composition & mask feathering; MIMT imblend demo)
simple lineardodge blend
insert text into an image (basic composition with figure capture or MIMT textim())