MATLAB: Concat images in order

image analysisimage processing

hello guys
i have 10 images of size 512×512
i need to concat 3 images at first for example
i want to concat 1st image and 2nd image and 3rd image in one image (like RGB form)
then i want to concat 2nd image and 3rd image and 4th image in one image to make the second image
then i want to concat 3rd image and 4th image and 5th image in one image to make the third image and so on
so the total number of images that should be obtained 8 images
can you please help me on that
thanks

Best Answer

Try this:
inputFolder = '/home/user/PycharmProjects/2.5dataconversion/images/patient_1';
outputFolder = '/home/user/PycharmProjects/2.5dataconversion/images/patient_2';
filePattern = fullfile(inputFolder, '*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles) - 2
% Read in image 1
baseFileName = theFiles(k).name;
fullFileName = fullfile(inputFolder, baseFileName);
image1 = imread(fullFileName);
% Read in image 2
baseFileName = theFiles(k+1).name;
fullFileName = fullfile(inputFolder, baseFileName);
image2 = imread(fullFileName);
% Read in image 3
baseFileName = theFiles(k+2).name;
fullFileName = fullfile(inputFolder, baseFileName);
image3 = imread(fullFileName);
% Now create an RGB image from those 3 gray scale images.
rgbImage = cat(3, image1, image2, image3);
% Write to disk
baseFileName = sprintf('image %2.2d.png', k);
outputFullFileName = fullfile(outputFolder, baseFileName);
imwrite(rgbImage, outputFullFileName);
end
Related Question