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
Best Answer