how to read multiple images and calculate mean?

14 views (last 30 days)
i want to input multiple images from a folder and then find mean image of those images?
  2 Comments
Geoff Hayes
Geoff Hayes on 25 Oct 2014
The reading of the multiple images from a folder should be straightforward, but you may want to clarify what you mean by find mean images of those images? Does each image have the same dimension? Are all in colour (RGB) or grayscale?
gurpreet kaur
gurpreet kaur on 25 Oct 2014
i am working on face recognition and i want to calculate the mean of three face images. yes each image have same dimension as 92x112. images are grayscale

Sign in to comment.

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 25 Oct 2014
Edited: Mohammad Abouali on 25 Oct 2014
There are two options:
1) If you don't have "Computer Vision Toolbox"
Then read the images as follow:
for i=1:nImages
imgSet{i}=imread(imageFilename{i});
end
where imageFilename store the path and file name to your images.
then you can calculate the mean of each image as follow
meanEachImage=cellfun(@(x) mean(x(:)), imgSet);
then mean of all images is:
meanImages=mean(meanEachImage);
you can combine the last to command into one command of course.
2) If you have "Computer Vision Toolbox"
first creat a imageSet as follow
imgSet=imageSet('Path to the folder containing all your images.')
then get the mean of each image as follow:
nBand=1;
meanEachImage=arrayfun(@(x) mean(reshape(imgSet.read(x),[],nBand)), (1:imgSet.Count)','UniformOutput',false);
then you can get the mean of all images by
meanImages=mean(cell2mat(meanEachImage));
The difference between this approach and the other one is that the first approach you load all your images in the memory, but in the second one you just load them one by one. So pretty much one image at a time is in the memory.
Although you can convert the first approach so that you only load one image at a time. Some thing like this would work
nBand=1
meanEachImage=cellfun(@(x) mean(reshape(imread(imageFilename{x}),[],nBand)), (1:nImage)','UniformOutput',false);
This would also load each image one by one and take the mean.
  5 Comments
sonia carole
sonia carole on 8 Dec 2015
yes i have visited this page here it is my file there is a lot of mismatches i think it is normal do not which method can help to solve it. since it not just to match them but to determine how many percent the current image has reference features code
%read the first image from the image set I=read(imgSet,1); %Initialize features for I(1) queryImage=rgb2gray( imresize(I,[300 300])); points=detectSURFFeatures(queryImage); strongest1=selectStrongest(points,20); [features,points]=extractFeatures(queryImage,strongest1); tforms(imgSet.Count) = projective2d(eye(3)); %Iterate over remaining images for i=2:imgSet.Count querypoints=points; queryfeatures=features; %read I(n_). I=read(imgSet,i); %detect and extract SURF features for I(n) grayImage=rgb2gray(imresize(I,[300 300])); points=detectSURFFeatures(grayImage); strongest2= selectStrongest(points,20); [feature,validpoints]=extractFeatures(grayImage,strongest2); detectfeatures=feature; detectpoints=validpoints; %find correspondences between queryImage and the rest of the images indexpairs=matchFeatures(queryfeatures,detectfeatures,'Unique',true); matchedPoints=querypoints(indexpairs(:,1),:); matchPointPrev=detectpoints(indexpairs(:,2),:); %figure;ax =axes; %showMatchedFeatures(queryImage,grayImage,matchedPoints,matchPointPrev,'montage','Parent',ax); %[tform ,inliersdetectpoints,inliersquerypoints]=... %estimateGeometricTransform(matchedPoints,matchPointPrev,'affine'); %figure; %showMatchedFeatures(queryImage,grayImage,inliersquerypoints,inliersdetectpoints,... %'montage');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!