MATLAB: How to add frame to image

image processingMATLAB

Hello everyone.
i would like to know how to combine the below images to be one ?
my interest is to add frames to image.
thank you.

Best Answer

Something like the code below should work. There are many ways to resize your image, below you'll find two examples.
frame=imread('frame4.jpg');
im=imread('Owl.jpg');
%select all white pixels in the frame
mask=all(frame>250,3);
%optional: select only the middle biggest blob
tmp=bwlabel(mask);
mask=tmp==tmp(round(end/2),round(end/2));
if true
%now we need to make the image the same size as the mask
im=imresize(im,size(mask));
else
%we could also resize it in a different way and pad it with zeros
mask_corners=[find(any(mask,2),1,'first') find(any(mask,2),1,'last') ...
find(any(mask,1),1,'first') find(any(mask,1),1,'last')];
im_inner=imresize(im,1+mask_corners([2 4])-mask_corners([1 3]));
im_pad=zeros([size(mask) 3],'like',frame);
im=im_pad;
im(mask_corners(1):mask_corners(2),...
mask_corners(3):mask_corners(4),:)=im_inner;
%or any other way that results in im being the same size as mask
end
%extend the mask to RGB
mask=repmat(mask,1,1,3);
%merge the images
out_im=frame;
out_im(mask)=im(mask);
imshow(out_im)