Find the average image of a set of images
93 次查看(过去 30 天)
显示 更早的评论
Hello,
I need to calculate the average image of a training set images but I don't have any idea how to do it.
Thank you in advance !
0 个评论
回答(5 个)
Image Analyst
2011-12-11
编辑:Image Analyst
2016-8-16
How about just doing a for loop:
for k = 1 : numberOfImages
thisImage = double(imread(files(k).filename)); % Or whatever...
[rows columns numberOfColorBands] = size(thisImage);
% First do a check for matching rows, columns, and number of color channels. Then:
if k == 1
sumImage = thisImage;
else
sumImage = sumImage + thisImage;
end
end
sumImage = sumImage / numberOfImages;
If you want, you can then either leave sumImage as double
imshow(sumImage, []); % Use []
or cast back to uint8 or uint16
sumImage = uint8(sumImage);
imshow(sumImage); % [] is optional now.
I do it all the time and it's fast
1 个评论
Image Analyst
2011-12-11
Referring to your answer, I hadn't seen your code yet. Obviously my files(k).filename should be your jpegFiles(k).name. Plus make sure you do the size check for robustness. It's not robust unless you check for that because it's dangerous to assume that all your images will be the same size. Even if they are, it can't hurt and makes it more robust should someone decide to borrow that snippet of code for another averaging app.
Kuno Meyer
2016-8-16
@Image Analys, you should also care about clipping. Use im2double() before accumulation and im2uint8() afterwards.
1 个评论
kavya k
2017-5-15
sir, i am trying to perform the averaging of 30 images . i am unable to clear that error can any one help me please......
0 个评论
kavya k
2017-5-15
sir, i am trying to perform the averaging of 30 images . i am unable to clear that error can any one help me please...... i have attached the .m file please once check and help me out
4 个评论
Image Analyst
2019-3-10
Well obviously thisImage is a different size than sumImage. What sizes are they? Look in the workspace, or use the size() function
[rows, columns, numberOfColorChannels] = size(sumImage)
[rows2, columns2, numberOfColorChannels2] = size(thisImage)
if isequal(size(sumImage), size(thisImage))
sumImage = sumImage + thisImage;
else
warningMessage = sprintf('Image sizes do not match.\nCheck sizes in the command window\n')
uiwait(errordlg(warningMessage));
return;
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!