MATLAB: How to stack image files if they are of different size

.tig imagesconcatenation

I am working with .tif images. they are of different sizes and there about 600 files.when i try to stack those images using 'for' loop, I am getting an error "Subscripted assignment dimension mismatch" because they do not agree with rows. column size is the same. I preallocate memory for the variable where the images should be stacked. still it is not happy. Please your help is much appreciated.

Best Answer

When you say 'stack', are you storing each image as a 'page' in some dimension? So you might have:
imageStack = nan( maxHeight, maxWidth, numColours, numImages );
Or are you stacking them vertically?
imageStack = nan( maxHeight * numImages, maxWidth, numColours );
In either case, what I'll suggest is that when you make your assignment, you need to subscript your image stack with a range that matches your image data (I'll use my first interpretation of image stack):
imageStack( 1:size(image,1), 1:size(image,2), 1:size(image,3), imno ) = image;
The same principle would apply in my second interpretation of imageStack, but your logic may be different depending on whether you allow slack space between images or you squeeze them together.