필터 지우기
필터 지우기

3D image stack; determine mean of individual arrays; error code

조회 수: 4 (최근 30일)
B Janssen
B Janssen 2018년 10월 5일
편집: Matt J 2018년 10월 9일
Hi,I have a 1000x1000x1952 uint8 3D image array (Array), and would like to get the mean value of each individual array "image" and subsequently put these in a 1952x1 array (meanArray).
The code I use is:
meanArray= mean(Array,[1 2])
the error code I get is: Error using sum "Dimension argument must be a positive integer scalar within indexing range. Error in mean (line 87) y = sum(x,dim,flag);"
What am I missing here? Thanks! Barry

채택된 답변

Matt J
Matt J 2018년 10월 5일
편집: Matt J 2018년 10월 5일
For some reason, mean was not written to let you operate along multiple dimensions in the same call. One alternative is to use sepblockfun (Download).
[m,n,p]=size(Array);
meanArray = sepblockfun(Array, [m,n,1], 'mean');
  댓글 수: 2
B Janssen
B Janssen 2018년 10월 8일
Hi Matt, Thanks for your response. I have tried the code and is works; however, your I have had some problems with calculating the min value and the max. It turns out that your solution is only a bit slower than Stephen's. I wish I could accept answers since they both work.
Matt J
Matt J 2018년 10월 9일
@Janssen, if you look inside sepblockfun, you will see that it is equivalent to Stephen's proposal, but more general, in that it allows you take means/maxes over different block sizes. There is some overhead from this additional flexibility, which is why you might see slightly slower performance.

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

추가 답변 (2개)

Stephen23
Stephen23 2018년 10월 5일
squeeze(mean(mean(Array,1),2))
  댓글 수: 2
B Janssen
B Janssen 2018년 10월 8일
HiStephen, Thanks for your response. (see my answer to Matt) I have tried your code and it works fine; moreover your solution is a bit faster Matt's. I wish I could accept answers since they both work. In the end I used your solution because of this time difference.
Stephen23
Stephen23 2018년 10월 9일
편집: Stephen23 2018년 10월 9일
@B Janssen: so you actually used my faster answer, but accepted Matt J's answer that you did not use? Confusing.
Note that you can also vote for answers, which is any easy way to show thanks to the volunteers who helped you. It is nice to get a vote as a small sign of appreciation.

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


Matt J
Matt J 2018년 10월 9일
편집: Matt J 2018년 10월 9일
This method would probably be most optimal, since it involves only one call to mean(), and therefore allocates a smaller chunk of memory for the output.
meanArray = mean( reshape(Array,[], size(Array,3)) );

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by