Borrar filtros
Borrar filtros

I want to cut/crop an RGB image and paste it on different location in another image

7 visualizaciones (últimos 30 días)
Hi, I would like to cut an RGB image and then paste it on another RGB image at different location.

Respuestas (1)

Wan Ji
Wan Ji el 25 de Ag. de 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 comentario
Jenifer NG
Jenifer NG el 18 de Mayo de 2022
I have an error with imcopy when my position is not interger number
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in imcopy (line 13)
B(Bx, By, :) = A(Ax, Ay, :); % copy part if A to B

Iniciar sesión para comentar.

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by