average image of set of image
Show older comments
i want to input multiple images with different size from a folder and then find the average image of those images? i try this code but it didn't give me any thing
imgSet=imageSet('C:\Users\User\Desktop\Jamila\master2Project\segmentationArticles\shapes');
nBand=1;
meanEachImage=arrayfun(@(x) mean(reshape(imgSet.read(x),[],nBand)), (1:imgSet.Count)','UniformOutput',false);
meanImages=mean(cell2mat(meanEachImage));
% imshow(meanImages,[]);
meanImages = uint8(meanImages);
imshow(meanImages,[]); % [] is optional now.
4 Comments
Adam
on 11 Jan 2017
What do you mean by 'it didn't give me any thing'? Do you mean you get a black image? or nothing plotted at all? Or an error? What are the values of meanImages? Do they need to be scaled rather than just cast to uint8?
What shape is meanImages? It would seem like it should be a vector rather than an image.
Jamila Osman
on 11 Jan 2017
Adam
on 11 Jan 2017
So what size is meanImages and what exactly is in it?
Jamila Osman
on 11 Jan 2017
Accepted Answer
More Answers (2)
Walter Roberson
on 11 Jan 2017
0 votes
You reshape each image into a row vector and mean that, which is going to give you a scalar result. You put that scalar into a cell. You have a column vector of x in your arrayfun so you will get out a column vector of cells each with a scalar. You convert that to a matrix with cell2mat which gives you a column vector. You mean() that, which gives you a scalar. You ask to display the scalar as an entire image.
If you want the average image then read the images but do not reshape or mean() yet. mean(cat(3,ResultingCell{:}), 3) to get the average image
2 Comments
Jamila Osman
on 11 Jan 2017
Walter Roberson
on 12 Jan 2017
imgSet = imageSet('C:\Users\User\Desktop\Jamila\master2Project\segmentationArticles\shapes');
allImages = arrayfun(@(x) imgSet.read(x), 1:imgSet.Count, 'UniformOutput', false);
ImageStack = cat(3, allImages);
meanImage = typecast( mean(ImageStack, 3), class(ImageStack) );
imshow(meanImage)
Jamila Osman
on 12 Jan 2017
0 votes
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!