How to insert picture 1 into picture 2?

29 ビュー (過去 30 日間)
Minh
Minh 2022 年 11 月 25 日
回答済み: Image Analyst 2022 年 11 月 30 日
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?

採用された回答

Vilém Frynta
Vilém Frynta 2022 年 11 月 25 日
編集済み: Vilém Frynta 2022 年 11 月 25 日
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 件のコメント
Vilém Frynta
Vilém Frynta 2022 年 11 月 26 日
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 2022 年 11 月 26 日
thank you very much, i will learn more 💗

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 11 月 30 日

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by