I want to cut/crop an RGB image and paste it on different location in another image
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I would like to cut an RGB image and then paste it on another RGB image at different location.
0 Kommentare
Antworten (1)
Wan Ji
am 25 Aug. 2021
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 Kommentar
Jenifer NG
am 18 Mai 2022
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!