MATLAB Answers

calculating error while averaging multiple images

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
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
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
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;
yLow = maxzeile-WINDOWSIZE;
if (maxzeile + WINDOWSIZE >= beamImageSize(1))
yHigh = beamImageSize(1);
yHigh = maxzeile+WINDOWSIZE;
if (maxspalte <= WINDOWSIZE)
xLow = 1;
xLow = maxspalte-WINDOWSIZE;
if (maxspalte + WINDOWSIZE >= beamImageSize(2))
xHigh = beamImageSize(2);
xHigh = maxspalte+WINDOWSIZE;
yLow = abs(round(yLow)); %disp(yLow)
yHigh = abs(round(yHigh)); %disp(yHigh)
xLow = abs(round(xLow)); %disp(xLow)
xHigh = abs(round(xHigh)); %disp(xHigh)
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)
beamIn(yLow:yHigh,xLow:xHigh) = 0; %beamIn(yLow:yHigh,xLow:xHigh)>10000;
n = n + 1;
[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)]);
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)]);
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);

Sign in to comment.

More Answers (2)

Image Analyst
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.

Sign in to comment.

Sumera Yamin
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?

Community Treasure Hunt

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

Start Hunting!