How to stack image files if they are of different size

2 vues (au cours des 30 derniers jours)
Kavitha Srinivasan
Kavitha Srinivasan le 22 Mai 2012
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.

Réponse acceptée

Geoff
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
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.
Kavitha Srinivasan
Kavitha Srinivasan le 22 Mai 2012
Thank you so much.
It worked now.
I could stack them as 3D image. May i get clarify this as well.
I really want to make them read as binary file inorder to input that file for reconstruction using someother function.
Though I could read them as binary file through 'fread', when I try to use 'reshape', I got an error "elements should be the same when using reshape". what does it mean?
Kindly help me.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by