How to add frame to image ?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
IJumperQ NoNeed
el 30 de Abr. de 2019
Comentada: IJumperQ NoNeed
el 1 de Mayo de 2019
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.
4 comentarios
Rik
el 1 de Mayo de 2019
I will not help you if you insist on not attaching example images. You should pad the image and then use logical indexing to only overwrite the pixels that are white in your frame image.
Respuesta aceptada
Rik
el 1 de Mayo de 2019
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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!