MATLAB: Concatenating images from image files

concatenationimagesloading files

Hello! I have a series of images saved in a folder, and I have written a short program to open two of these image files, concatenate them (preferably vertically, although for now I am trying horizontally), then save this new image to the same folder. This is what I have written so far:
function concatentateImages
%this is the folder where the original images are located path='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = strcat(cr45e__ch_21', '.pdf');
[image1,map1] = imread(graph1);
file2 = strcat('cr45f__ch_24', '.jpg');
[image2,map2] = imread(graph2);
image1 = ind2rgb(image1,map1);
image2 = ind2rgb(image2,map2);
image3 = cat(2,image1,image2);
%this is the directory where I want to save the new images
dircase=('/home/packremote/SharedDocuments/Amina/zEXAMPLE/');
nombrejpg=strcat(dircase, 'test', jpgext)
saveas(f, nombrejpg, 'jpg')
fclose('all');
However, I keep getting an error that my files do not exist, though I am certain the names are copied correctly.
I am currently using jpg files, but the format can be easily converted.
Any input on how to fix this error, or a nicer way of preforming this task is greatly appreciated!
Cheers,
Amina

Best Answer

iwidth = max(size(image1,2),size(image2,2));
if size(image1,2) < iwidth
image1(1,iwidth,1) = 0;
end
if size(image2,2) < iwidth
image2(1,iwidth,1) = 0;
end
image3 = cat(1,image1,image2);