简体   繁体   中英

How can I concatenate images in one matrix in MATLAB?

I have 64 images (Their names are like that: 00001.jpg, ... , 00064.jpg). I want to create a matrix with these images which would give the result below:

[img1 img2 ... img8
 img9 img10 ...img16
 ...
 img57 ........img64]

I've tried horzcat(), imtile(), montage() methods, but these gave me the results I didn't want.

I expect a 8x8 matrix with images. I want to do above programmatically using Matlab but couldn't find any solution.

How can I do this? Thank you!

An image is basically a matrix.

This is how you concatenate 2 matrices ( link )

A = ones(1,4);
B = zeros(1,4);
C = [A B];  //Horizontal
D = [A; B]; //Vertical

Use this logic to join your matrices horizontally and vertically.

Said that, You should be aware of matrix size and its mis-match problems.

The function imtile is what you want. It's your expectation of an 8x8 size that is incorrect. Take the following example.

A = magic(2);

>> imtile({A,A,A,A})

ans =

 1     3     1     3
 4     2     4     2
 1     3     1     3
 4     2     4     2

Since imtile accepts an ImageDatastore, the easiest thing to do would be:

imds = imageDatastore(pathToYourImages)
tiledImage = imtile(imds);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM