- you did not include the folder when sending the filename to imread(), and
- you did not use the right variable (files instead of theFiles) and
- you did not have the right structure member off files (should be name, not myFolder),
Average image of a folder of images
5 views (last 30 days)
Show older comments
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;
0 Comments
Answers (1)
Image Analyst
on 10 Jan 2016
Instead of this:
thisImage=imread(files(k).myFolder);
where
try this:
fullFileName = fullfile(myFolder, theFiles(k).name);
thisImage=double(imread(fullFileName)); % Be sure to cast to double to prevent clipping.
3 Comments
Image Analyst
on 10 Jan 2016
See my attached demo, which averages all gray scale or RGB images in a folder.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!