It is easier if all the images are of same dimensions. If not, find the largest dimension on each side(x,y) and zeropad all the images accordingly. If you have n images then your 4D image matrix I should be (x,y,3,n). You can then write a for loop where you can use imread to read in the RGB images one by one. To later access each image, refer to this link: https://www.mathworks.com/matlabcentral/answers/403554-accessing-multiple-images-in-4d-array