How to insert picture 1 into picture 2?

21 visualizaciones (últimos 30 días)
Minh
Minh el 25 de Nov. de 2022
Respondida: Image Analyst el 30 de Nov. de 2022
I want to use matrix insertion method to insert an image taken by a webcam (640x480) into another image with a larger resolution, how should I do that?

Respuesta aceptada

Vilém Frynta
Vilém Frynta el 25 de Nov. de 2022
Editada: Vilém Frynta el 25 de Nov. de 2022
Example:
% Using random pictures that are part of Matlab
img1 = imread("peacock.jpg"); % Smaller picture (792 x 1056)
img2 = imread("flamingos.jpg"); % Larger picture (972 x 1296)
img1_Resolution = size(img1)
We know picture sizes. Now you need to choose where you want to insert the picture and use indexing to overwrite part of the img2 by img1.
I have chosen to insert to position 51–842 on X axis and 123–1279 on Y axis.
imgNew = img2; % Saving larger picture into new variable
% X_position defines where you insert new picture on X axis
X_position = 51:50+img1_Resolution(1);
% Y_position defines where you insert new picture on Y axis
Y_position = 123:122+img1_Resolution(2);
% Inserting smaller picture into the larger one on defined positions
imgNew(X_position, Y_position,:) = img1;
subplot(2,2,1)
imshow(img1)
subplot(2,2,2)
imshow(img2)
subplot(2,2,[3 4])
imshow(imgNew)
Hope this helps. I will edit this to be more understandable, just wanted to post this to save my answer progress.
Edit: aesthethics
  6 comentarios
Vilém Frynta
Vilém Frynta el 26 de Nov. de 2022
X position on your frame corresponds to horizontal length of the green area on your picture Y position corresponds to vertical length of the green area
with these 2 things, you are telling Matlab where you want to insert the picture.
I recommend you to educate yourself on “Image Processing Toolbox”, prefferably in your best language, to understand better.
Minh
Minh el 26 de Nov. de 2022
thank you very much, i will learn more 💗

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by