how to averging the average the images in the folder

3 visualizaciones (últimos 30 días)
태원 최
태원 최 el 29 de Nov. de 2023
Editada: DGM el 29 de Nov. de 2023
I want to average the 3000 images in the folder. Anyone know how to averaging the image in matlab?

Respuestas (2)

DGM el 29 de Nov. de 2023
There are plenty of examples of how to do this already on the forum. Here's another.
% some example images in the demo directory
basepath = fullfile(matlabroot,'toolbox/images/imdata');
S = dir(fullfile(basepath,'AT3*.tif'));
nfiles = numel(S);
for f = 1:nfiles
thisfname = fullfile(basepath,S(f).name);
thisimage = imread(thisfname);
if f == 1
expectedsize = size(thisimage,1:4);
expectedclass = class(thisimage);
averageimage = double(thisimage);
sizeisbad = ~all(size(thisimage,1:4) == expectedsize);
classisbad = ~strcmp(class(thisimage),expectedclass);
if sizeisbad
error('image size is inconsistent')
if classisbad
error('image class is inconsistent')
averageimage = averageimage + double(thisimage);
averageimage = cast(averageimage/nfiles,expectedclass);

Image Analyst
Image Analyst el 29 de Nov. de 2023
See my attached demo.
  3 comentarios
Image Analyst
Image Analyst el 29 de Nov. de 2023
  1. @Dyuman Joshi the file format doesn't matter. Once they're read in with imread, they're just matrices.
  2. If they're not the same size, it resizes all images to match the size of the first image.
  3. If some images are gray scale, it converts them to RGB so they can be summed in.
  4. I do not scale the images. Normally all the images you want to average are all uint8 or uint16 however they don't have to be and the program doesn't require it. However, it does not scale intensities to be either 0-255 or 0-65535, it just adds them in as their original value. If that's a concern then they could have their intensities all scaled to uint16 by multiplying the uint8 images by 256.
DGM el 29 de Nov. de 2023
Editada: DGM el 29 de Nov. de 2023
I take the position that mismatches of geometry, depth, or class indicate an improper comparison.
While I'm ready to feed an int16 I image and a uint8 RGBA image to imblend() for purely visual purposes, I assume that an average of an imageset for technical purposes should rely on the image content being properly registered, which means that they are the same geometry. Likewise, I would expect them to be the same depth. We could take the average of peppers.png and an expanded, stretched copy of cameraman.tif, but it doesn't mean anything.
If size and depth are consistent, it's likely that class should also be consistent. Otherwise, it should be simple enough to convert everything to unit-scale double on the way in instead of trying to preserve class by using an improperly-scaled floating point image. The use of improperly-scaled floats is only attractive because IPT doesn't have a parametric version of im2double()/im2uint8() etc.
In any case, the contextual meaning of the average is yet unknown, and the importance of meaning is also unknown.

Iniciar sesión para comentar.


Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by