How to stack image files if they are of different size
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Geoff
le 22 Mai 2012
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 commentaires
Geoff
le 22 Mai 2012
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.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!