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!