Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Yuan Yuan Lin
Yuan Yuan Lin le 12 Nov 2020
Commenté : Setsuna Yuuki. le 13 Nov 2020
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.

Réponse acceptée

Setsuna Yuuki.
Setsuna Yuuki. le 12 Nov 2020
Modifié(e) : Setsuna Yuuki. le 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 commentaires
Yuan Yuan Lin
Yuan Yuan Lin le 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. le 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)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by