Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Setsuna Yuuki.
Setsuna Yuuki. am 12 Nov. 2020
Bearbeitet: Setsuna Yuuki. am 12 Nov. 2020
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 Kommentare
Yuan Yuan Lin
Yuan Yuan Lin am 13 Nov. 2020
[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. am 13 Nov. 2020
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by