# calculating error while averaging multiple images

6 views (last 30 days)
Sumera Yamin on 30 Jul 2020
Commented: Image Analyst on 17 Aug 2020
Hi, I have a simple problem and needs guidance. I have 15 image files. I want to calculate the average of these images and calculate error on these images. Any help is appreciated.

Walter Roberson on 9 Aug 2020
Do you want the average of the R, G, and B separately for each image?
Are you asking for averages to be taken over time for each pixel's R, G, B components?
Read the images into a 4D array, rows by columns by colorpanes by image_number . Then mean(Stack,4) or std(Stack, [], 4)
Sumera Yamin on 12 Aug 2020
so i took this part of code and did the furthur processing of my data. combining with the above function, the code is as shown below. The problem is that for i want to use both imageData and imgstd for calculating [maxzeile, maxspalte] and [maxzeile_err, maxspalte_err] respectively. My code however takes imageData for calculating both and hence giving me the same output. Could you please pointout how should i change the code to use both imagedata and imgstd.
function [maxzeile, maxspalte, maxzeile_err, maxspalte_err, xRMS, yRMS] = findBeam(beamIn, windowsize, threshold, maxIterations)
%rough beam position
BEAMFOUND = 0;
WINDOWSIZE = windowsize/2;
THRESHOLD = round(threshold*WINDOWSIZE^2);
n = 0;
beamImageSize = size(beamIn);
while (BEAMFOUND == 0 && n <= maxIterations)
[maxwerte, maxzeilen] = max(beamIn);
[maxwert, maxspalte] = max(maxwerte);
maxzeile = maxzeilen(maxspalte);
if (maxzeile <= WINDOWSIZE)
yLow = 1;
else
yLow = maxzeile-WINDOWSIZE;
end
if (maxzeile + WINDOWSIZE >= beamImageSize(1))
yHigh = beamImageSize(1);
else
yHigh = maxzeile+WINDOWSIZE;
end
if (maxspalte <= WINDOWSIZE)
xLow = 1;
else
xLow = maxspalte-WINDOWSIZE;
end
if (maxspalte + WINDOWSIZE >= beamImageSize(2))
xHigh = beamImageSize(2);
else
xHigh = maxspalte+WINDOWSIZE;
end
yLow = abs(round(yLow)); %disp(yLow)
yHigh = abs(round(yHigh)); %disp(yHigh)
xLow = abs(round(xLow)); %disp(xLow)
xHigh = abs(round(xHigh)); %disp(xHigh)
%disp('------')
window = beamIn(yLow:yHigh,xLow:xHigh); %figure(n+5); imagesc(window);
% Intensity cut
thre = 0.75 * max(max(window));
beamArea = sum(sum(window>thre));
if (beamArea >= THRESHOLD)
BEAMFOUND = 1;
else
beamIn(yLow:yHigh,xLow:xHigh) = 0; %beamIn(yLow:yHigh,xLow:xHigh)>10000;
end
n = n + 1;
end
[xRMS, yRMS] = beamRMS(window);
beamImageSize = size(beamIn(yLow:yHigh,xLow:xHigh));
beamX = 1:beamImageSize(2);
beamY = 1:beamImageSize(1);
totalMass = sum(sum(beamIn(yLow:yHigh,xLow:xHigh)));
centerOfMass = zeros(1,2);
for i=1:length(beamX)
for j=1:length(beamY)
centerOfMass = centerOfMass + double(window(j,i)).*double([beamY(j),beamX(i)]);
end
end
centerOfMass = centerOfMass / totalMass;
centerOfMass = round(centerOfMass);
centerOfMass = centerOfMass + [yLow,xLow];
maxzeile = centerOfMass(1);
maxspalte = centerOfMass(2);
%error in center of mass:
beamImageSize_err = size(beamIn(yLow:yHigh,xLow:xHigh));
beamX_err = 1:beamImageSize_err(2);
beamY_err = 1:beamImageSize_err(1);
totalMass_err = sum(sum(beamIn(yLow:yHigh,xLow:xHigh)));
centerOfMass_err = zeros(1,2);
for i=1:length(beamX_err)
for j=1:length(beamY_err)
centerOfMass_err = centerOfMass_err + double(window(j,i)).*double([beamY_err(j),beamX_err(i)]);
end
end
centerOfMass_err = centerOfMass_err / totalMass_err;
centerOfMass_err = round(centerOfMass_err);
centerOfMass_err = centerOfMass_err + [yLow,xLow];
maxzeile_err = centerOfMass_err(1);
maxspalte_err = centerOfMass_err(2);
end

Image Analyst on 10 Aug 2020
Edited: Image Analyst on 12 Aug 2020
See my attached demo. It averages RGB and gray scale images and gives statistics about them.. Adapt as needed.
Image Analyst on 17 Aug 2020
See attached.

Sumera Yamin on 11 Aug 2020
many thanks for this analyzer, it gives me attached error. Also what is mask and what does clear mask does?