Matrix Algebra without Loop
이전 댓글 표시
I'm trying to do a relatively simple calculation, but my linear algebra is a bit rusty, and I'd like to know if it can be done without a loop. I'm taking a 3D image stack and I want to subtract the image frame average from each pixel in that frame to correct the variance for irradiance variation between frames during the collection. There is slightly more to the formula than what I show, but this is the only part in which I can't figure out how to avoid a loop.
One thought I had was to take the frame average (1D vector) and convert into a 3D matrix with each 2D frame repeating a single value from the 1D frame average to fill the matrix so that I could subtract one matrix directly from the other and square the result. This seems cumbersome though.
Thanks in advance for any elegant solutions!
imgVarCorrectedSum = zeros(nRow,nCol);
for i= 1:nFrames
imgVarCorrectedSum(:,:) = imgVarCorrectedSum(:,:) + ...
( imgActive(:,:,i) - imgAvgFrame(i) ).^2;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!