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!