Matlab – How to concatenate many RGB images into one image in MATLAB

image processingMATLAB

I have a hundred equal sized RGB images numbered from 1 to 100. I want to create one image out of them. For example, if I give row=10 and column=10 then the output should be such that the first 10 images will form the first row and so on.

Best Answer

One way is to create a 10-by-10 cell array containing your images, and then to use CELL2MAT to catenate them into a large image.

nRows = 10;
nCols = 10;
imgCell = cell(nRows,nCols);

for iImage = 1:nRows*nCols

%# construct image name - fix this like so it conforms to your naming scheme
%# also, add the path if necessary
imageName = sprintf('image%i.jpg',iImage);

%# add the image to imgCell
%# images will filled first into all rows of column one
%# then into all rows of column 2, etc
imgCell{iImage} = imread(imageName);

end

%# if you want the images to be arranged along rows instead of 
%# columns, you can transpose imgCell here
%# imgCell = imgCell';

%# catenate into big image
bigImage = cell2mat(imgCell);

%# show the result
imshow(bigImage)