필터 지우기
필터 지우기

How to create an array and combine and put two images into it

조회 수: 3 (최근 30일)
Yuan Yuan Lin
Yuan Yuan Lin 2020년 11월 12일
댓글: Setsuna Yuuki. 2020년 11월 13일
Hi.
So far, I have the following code:
A = imread('Yuan.jpg');
ACrop = A(300:1300, 300:1051);
imshow(ACrop)
B = imread('Jacky.jpg');
BCrop = B(1:225, 88:283);
imshow(BCrop)
I have two images cropped. I want to combine ACrop and BCrop together with ACrop on the left and BCrop on the left. How do I create an array so that I may combine two images into one in the array?
Thanks.

채택된 답변

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 12일
편집: Setsuna Yuuki. 2020년 11월 12일
Maybe you need to resize or add white pixels so that the images have the same dimension.
A = imread('Yuan.jpg');
ACrop = A(300:1300, 300:1051);
imshow(ACrop)
B = imread('Jacky.jpg');
BCrop = B(1:225, 88:283);
imshow(BCrop)
[qq,ww,ee] = size(Acrop);
matrix = 255*uint8(ones(qq,ww,ee)); %Image with pixels in 255 (White)
[rr,tt,yy] = size(Bcrop);
matrix(1:rr,1:tt,:) = Bcrop(:,:,:); %add Bcrop to the white matrix
umi = [ACrop, matrix]; %concatenate
imshow(umi)
%or
umi = [ACrop;matrix]; %concatenate
imshow(umi)
with resize:
A = imread('Yuan.jpg');
ACrop = A(300:1300, 300:1051);
imshow(ACrop)
B = imread('Jacky.jpg');
BCrop = B(1:225, 88:283);
imshow(BCrop)
[qq,ww,ee] = size(Acrop);
Bcrop = imresize(Bcrop,[qq ww]);
umi = [ACrop, Bcrop]; %concatenate
imshow(umi)
%or
umi = [ACrop;Bcrop]; %concatenate
imshow(umi)
  댓글 수: 6
Yuan Yuan Lin
Yuan Yuan Lin 2020년 11월 13일
[qq, ww, ee] = size(ACrop);
BCrop = imresize(BCrop, [qq, ww]);
final = [ACrop, BCrop];
The ee value is the channel that has been added. Tried adding ee to [qq, ww] for BCrop but the combined image is still black and white. final = [ACrop, BCrop, :]; doesn't seem to be the correct way of writing it. Any way to write it so that it retains its rgb?
Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 13일
when you crop the image, you must do with 3 channels.
A = imread('Yuan.jpg');
ACrop = A(300:1300, 300:1051,:);% : --> 3 channels
imshow(ACrop)
B = imread('Jacky.jpg');
BCrop = B(1:225, 88:283,:); % : --> 3 channels
imshow(BCrop)
[qq,ww,~] = size(ACrop);
Bcrop = imresize(BCrop,[qq ww]);
umi = [ACrop, Bcrop]; %concatenate
imshow(umi)
%or
umi = [ACrop;Bcrop]; %concatenate
imshow(umi)

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by