![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180064/image.png)
How to merge two images of different sizes ??
12 次查看(过去 30 天)
显示 更早的评论
How to merge two images of different sizes so that the resultant merged image contains bigger image contains smaller image at a specific location in bigger image ??
0 个评论
采纳的回答
Michal Dobai
2017-12-13
You can just index elements in bigger image and assign them values of smaller image.
combinedImage = biggerImage;
s = size(smallerImage);
combinedImage(x:x+s(1)-1, y:y+s(2)-1, :) = smallerImage;
This example works only if smaller image fits entirely into bigger image after placed to specific location!
If you want be able to put smaller image to location that part of it will be outside of bigger image, you have to handle this case properly. There are more options you can do. You can extend bigger image (and set some background color) or crop smaller image.
Whole example code:
% 'specific location' point
x = 123;
y = 274;
% create example images
biggerImage = rand(512,512,3);
smallerImage = ones(64,64,3);
% merge images
combinedImage = biggerImage;
s = size(smallerImage);
combinedImage(x:x+s(1)-1, y:y+s(2)-1, :) = smallerImage;
imshow(combinedImage);
Result:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180064/image.png)
0 个评论
更多回答(1 个)
Image Analyst
2017-12-13
See my copy and paste demos to paste rectangular and freehand images onto a larger image.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Camera Calibration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!