how to read multiple images and calculate mean?

i want to input multiple images from a folder and then find mean image of those images?

2 Comments

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?
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

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

please Prof.Mohammad Abouali in case we want to detectSURFFeature on each image with ImageSet how can i do it? I have tried with the same code to calculate the mean is not running
It is the same procedure. This is the general pseudo-code
for idx=1:nImages
% read idx-th image if you haven't already
% perform calculations including detectSURFF on idx-th image.
% store the results to a file or in a variable
end
Thank you professor,i have another question. Actually my goal is to make image classifications by taking one image as target detect and extract features then compare with the others images(features also) in the data set. my image data set contains image of the same object with different views Obviously because camera moved the image content also changes, how can i find the correspondence features of my target image and the image data set likewise : comparison between reference-image3 (you can check the attached file) result 30% features of the reference to make a classification from the most closest to the least one.
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)

Categories

Community Treasure Hunt

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

Start Hunting!