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

3 次查看(过去 30 天)
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