필터 지우기
필터 지우기

Average image of a folder of images

조회 수: 5 (최근 30일)
Gee Cheng Mun
Gee Cheng Mun 2016년 1월 10일
댓글: Marcela pena 2018년 3월 26일
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;

답변 (1개)

Image Analyst
Image Analyst 2016년 1월 10일
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
Image Analyst
Image Analyst 2016년 1월 10일
See my attached demo, which averages all gray scale or RGB images in a folder.
Marcela pena
Marcela pena 2018년 3월 26일
Thanks for the script !!!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by