フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by