How to find the average of 3D matrices in a cell?

조회 수: 5 (최근 30일)
Nilesh
Nilesh 2022년 12월 1일
댓글: Walter Roberson 2022년 12월 2일
Hello everyone,
I wish to average the 3D matrices in a cell array?
Each is a 2048 by 2048 by 100 matrix, which looks like this:
What I wish is to average each 3D matrix over the z axis (over 100), as shown below.
This will eventually lead to 1 by 3 cell, but this time, only 2048 by 2048 pixels.
The code that I have used is as follows:
for iB=1:numel(B)
meanB{iB}=mean(B{iB},3); % B is the 3D matrix
end
I have cross-cheked the values, but have found that I am not getting the right values. They are much smaller than expected.
Can anyone please help with this?
Kind regards,
Anshul

답변 (1개)

Walter Roberson
Walter Roberson 2022년 12월 1일
The code you already have should work. Or you could use the more compact
meanB = cellfun(@(b) mean(b,3), B, 'uniform', 0);
If the values are much smaller than expected, then re-check by commanding
format long g
and then examining the contents at the command line (not in the variable browser.)
  댓글 수: 2
Nilesh
Nilesh 2022년 12월 2일
Okay thank you very much.
I am still not getting the right values. Would you know if this is the correct way to create the 1 by 3 cell of 3D matrices (as shown in the first image). To do so, I have used the following:
filenum=[30, 35, 40]
B{filenum}(:,:,K)=A;%where K is length of images (100 in this case), and A reads each individual image
B=B(~cellfun('isempty',B))%Removes empty matrices
Some background imformation, there are three folders each contain 100 2D images, A is a function that reads all the images from each folder. B is the above matrix shown in the first diagram above.
I doubt this might be where the problem is coming from.
Walter Roberson
Walter Roberson 2022년 12월 2일
That looks like it would work to create a 1 x something cell array. K would need to be varying from 1 to 100 .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by