how to create stack with multiple images?

Hi all,
I have a series of images and I want to make stacks of the images. The dimension of the stack should be like 2490*2490*7.
Here is the code I worte.
b=cell(7,9);
I_max=cell(7,9);
I_stack_store=cell(9,1);
I_stack=zeros(2975,2975,7);
for t=1:9
for i=1:7
I=imread(['calibrate2-P01.00' num2str(t) '00' num2str(i) '.tif']);
b{i,t}=I;
I_max{i,t}=max(b{i,t},[],3);
I_stack(:,:,7)=I_max{:,t};
I_stack_store{t}=I_stack;
end
end
I_max is a 7x9 array with each cell one image. (e.g. 2490*2490)
I want to get every column (7 images) of I_max into a stack, resulting 9 stacks which can be stored into a new array.
There must be something wrong with my code because I did not have the image l want.
Can someone help?
Thanks a lot!

 Akzeptierte Antwort

VBBV
VBBV am 3 Aug. 2023
Bearbeitet: VBBV am 3 Aug. 2023
b=cell(7,9);
I_max=cell(7,9);
I_stack_store=cell(9,1);
for t=1:9
for i=1:7
I= rand(50,10,3);
b{i,t}=I;
I_max{i,t}=max(b{i,t},[],3);
I_stack(:,:,i)=I_max{i,t}; % I_stack(:,:,7) if you only want the 7th col
end
I_stack_store{t}=I_stack;
end
I_stack_store
I_stack_store = 9×1 cell array
{50×10×7 double} {50×10×7 double} {50×10×7 double} {50×10×7 double} {50×10×7 double} {50×10×7 double} {50×10×7 double} {50×10×7 double} {50×10×7 double}

6 Kommentare

VBBV
VBBV am 3 Aug. 2023
Bearbeitet: VBBV am 3 Aug. 2023
Assign the inner for loop index to
I_stack(:,:,i)=I_max{i,t}; % use i for loop index to store max values
I_stack_store{t}=I_stack; %
Thank you for the answer.
I can get the dementionality, but I was not sure if the stacks are getting the correct images. I am not sure either if my code is getting the images into stacks properly.
I_stack(:,:,i)=I_max{i,t}; % I am not sure if this code gets correct images into stacks
I_max is a 7x9 array with correct images in every array.
I want to get every column (7 images) into a stack, resulting 9 stacks with correct images.
Can you please have a look if the code is doing what I describe here?
Thank you!
VBBV
VBBV am 3 Aug. 2023
Bearbeitet: VBBV am 3 Aug. 2023
Yes, the code seems to do what you described. You can see the stack of 9 images as the output. However, there is one difference, please note this line
I_stack_store{t}=I_stack;
needs to be in outer for loop. This will essentially get all the correct images into one stack, which is 9 x 1 as seen from output. But If you use
I_stack(:,:,7)=I_max{:,t};
it will only store the last image ignoring other images.
I_stack(:,:,7)=I_max{:,t};
it will only store the last image ignoring other images.
Exactly this is the problem I want to fix. Is there a way that I can get 7 images into I_stack?
VBBV
VBBV am 3 Aug. 2023
The code I shown will do what you want. Please see the output I shown.
Yunwei
Yunwei am 3 Aug. 2023
Thanks!
I overlooked the difference between the code you shown and l attached in the first place.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Aug. 2023

Kommentiert:

am 3 Aug. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by