Azzera filtri
Azzera filtri

Average image of a folder of images

5 visualizzazioni (ultimi 30 giorni)
Gee Cheng Mun
Gee Cheng Mun il 10 Gen 2016
Commentato: Marcela pena il 26 Mar 2018
I am trying to obtain the average image for this folder of multiple images.
My code is as shown, however there is an error -> thisImage=imread(files(k).myFolder);
myFolder='E:\FYP2\Time Frames\Frame 13';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.png');
theFiles = dir(filePattern);
numberOfImages=length(theFiles);
for k=1 : numberOfImages
thisImage=imread(files(k).myFolder);
[rows, columns, numberOfColorBands]=size(thisImage);
if k == 1
sumImage = thisImage;
else
sumImage = sumImage + thisImage;
end
end
sumImage = sumImage / numberImages;

Risposte (1)

Image Analyst
Image Analyst il 10 Gen 2016
Instead of this:
thisImage=imread(files(k).myFolder);
where
  1. you did not include the folder when sending the filename to imread(), and
  2. you did not use the right variable (files instead of theFiles) and
  3. you did not have the right structure member off files (should be name, not myFolder),
try this:
fullFileName = fullfile(myFolder, theFiles(k).name);
thisImage=double(imread(fullFileName)); % Be sure to cast to double to prevent clipping.
  3 Commenti
Image Analyst
Image Analyst il 10 Gen 2016
See my attached demo, which averages all gray scale or RGB images in a folder.
Marcela pena
Marcela pena il 26 Mar 2018
Thanks for the script !!!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by