calculating error while averaging multiple images

1 Ansicht (letzte 30 Tage)
Sumera Yamin
Sumera Yamin am 30 Jul. 2020
Kommentiert: Image Analyst am 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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)
  12 Kommentare
Walter Roberson
Walter Roberson am 12 Aug. 2020
function [imageData, imgstd] = meanImage(path, fileNamePrefix, fileNameSufix, n, mStart, mEnd)
N = mEnd - (mStart - 1);
currentImage = double(loadImage(path, fileNamePrefix, fileNameSufix, n, mStart));
imgsum = currentImage;
imgsqsum = imgsum.^2;
for mm = (mStart+1):mEnd
currentImage = double(loadImage(path, fileNamePrefix, fileNameSufix, n, mm));
imgsum = imgsum + currentImage;
imgsqsum = imgsqum + currentImage.^2;
end
mean_img = imgsum ./ N;
imageData = cast(mean_img, class(currentImage));
imgstd = sqrt((imgsqsum - 2 .* mean_img .* imgsum + mean_img.^2) ./ (N-1));
end
This code deliberately turns the mean image back into the datatype of the individual images, such as uint8. This is because it calculates the mean image in the same units as the original image, not in terms of the 0 to 1 range that could be used instead. Whether this is best for you depends on what you want to do with the mean image.
Sumera Yamin
Sumera Yamin am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 10 Aug. 2020
Bearbeitet: Image Analyst am 12 Aug. 2020
See my attached demo. It averages RGB and gray scale images and gives statistics about them.. Adapt as needed.
  11 Kommentare
Sumera Yamin
Sumera Yamin am 16 Aug. 2020
hi, thanks for your answer, this error gone now, but gui give me another (attached) message, however if i ignore the message, the gui does analyze the images.

Melden Sie sich an, um zu kommentieren.


Sumera Yamin
Sumera Yamin am 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!

Translated by