- 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 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Image Analyst
2016년 1월 10일
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
Image Analyst
2016년 1월 10일
See my attached demo, which averages all gray scale or RGB images in a folder.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!