How to insert picture 1 into picture 2?
24 次查看(过去 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?
0 个评论
采纳的回答
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
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.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!