I want to cut/crop an RGB image and paste it on different location in another image
3 次查看(过去 30 天)
显示 更早的评论
Hi, I would like to cut an RGB image and then paste it on another RGB image at different location.
0 个评论
回答(1 个)
Wan Ji
2021-8-25
I will show you how to copy Part of image A to a certain position of image B
clc;clear
A = imread('Lena.jpg');
A = imresize(A,[200,200]);
imshow(A)
B = uint8(ones(600,600,3)*255); % create an empty image to get the copy from A
figure(1); clf; imshow(B)
title('Empty white image: the target image')
% copy Part of image A to image B
copyLen = 160; copyWid = 120;
copyPosAx = 11; copyPosAy = 31; % the pos coordinate
copyPosBx = 21; copyPosBy = 21;
% copy for the first time
B = imcopy(A, B, [copyPosAx, copyPosAy], [copyPosBx, copyPosBy], [copyLen, copyWid]);
figure(2); clf; imshow(B); title('After copy once')
copyPosBx = 201; copyPosBy = 201; % change the copy position of image B
% copy for the second time
B = imcopy(A, B, [copyPosAx, copyPosAy], [copyPosBx, copyPosBy], [copyLen, copyWid]);
figure(3); clf; imshow(B); title('After copy twice')
copyPosBx = 391; copyPosBy = 301; % change the copy position of image B
% copy for the third time
B = imcopy(A, B, [copyPosAx, copyPosAy], [copyPosBx, copyPosBy], [copyLen, copyWid]);
figure(4); clf; imshow(B); title('After copy third time')
The imcopy function is used for three times, after that, you can see how Lena's profile show in a white image with 3 times
Wish you like it.
1 个评论
Jenifer NG
2022-5-18
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!