How to stack image files if they are of different size
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Geoff
2012-5-22
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.
3 个评论
Geoff
2012-5-22
Right, so that's my first interpretation, except it seems that you have monochrome images (ie you can remove the 3rd dimension that handles colour channels). I am assuming that when an image contains fewer rows, you align it along the top edge. If you wanted to align on the bottom edge or centre it, that's a trivial change to the code.
Just to be clear here, do this:
imageStack( 1:size(image,1), 1:size(image,2), imno ) = image;
Where 'image' is one image that you have read in your for-loop, and 'imno' is the loop iteration variable.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!