필터 지우기
필터 지우기

How To Combine Cropped Image to the Original Image?

조회 수: 3 (최근 30일)
WanYu
WanYu 2020년 2월 8일
댓글: KSSV 2020년 2월 10일
Hi All,
I have cropped out a part from my original image and wish to combine it back to the original image.
A 36 by 36 image is cropped from the original image, A then I wish to combine it back to the exact position as it was cropped earlier.
Code as shown:
square = [55 88 35 35];
A = imread (label);
A = imcrop(A, square);
Anyone could please tell me how...
Thank you.

채택된 답변

KSSV
KSSV 2020년 2월 8일
I = imread('cameraman.tif') ; % read image
[I1,rect] = imcrop(I) ; % crop the image
nx = round(rect(1)) ; % location
ny = round(rect(2)) ; % location
w = size(I1,2) ; % width
h = size(I1,1) ; % height
% replace
I(ny:ny+h-1,nx:nx+w-1,:) = I1+100 ;
  댓글 수: 2
WanYu
WanYu 2020년 2월 8일
Hi,
Thanks for answering.
However, I do face errors as: Unable to perform assignment because the size of the left side is 108-by-36-by-3 and the size of the right side is 36-by-36-by-3.
My code is shown as below:
square_x = 55;
square_y = 88;
square = [square_x square_y 35 35];
A = imread (label);
A = imcrop(A, square);
I am trying to replace the cropped image with a new image at the same coordinates as the cropped image, so there is "rgb2".
[width height] = size(rgb2);
A(square_y : (square_y + height - 1), square_x : (square_x + width - 1), :) = rgb2;
KSSV
KSSV 2020년 2월 10일
square_x = 55;
square_y = 88;
square = [square_x square_y 35 35];
A = imread (label);
rgb2 = imcrop(A, square);
[width height] = size(rgb2);
A(square_y : (square_y + height - 1), square_x : (square_x + width - 1), :) = rgb2;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by