# find the average pixel value of matrix of images

27 views (last 30 days)
michael bowen on 17 Dec 2021
Commented: Konrad on 17 Dec 2021
hi i was wondering how to put a group of 10 images that are 1920 x 1080 into a matrix that is size 1920x1080x10. Im doing this to keep track of values for each pixel.
i have tried
for i = 1:10
outputFileName = sprintf('bwImage%d.jpg', i);
end
B = mean(allImages);
but this creates and matrix size 1 x 10.
This matrix will be used to calculate the average value at each pixel location

Edited: Konrad on 17 Dec 2021
Hi Michael,
allImages{i} = ... creates a cell-array containing the images.
If your images are all grayscale and of the same size you can use a 3-d array:
for i = 1:10
outputFileName = sprintf('bwImage%d.jpg', i);
allImages(:,:,i) = imread(outputFileName); % concatenate images in 3rd dimension
end
B = mean(allImages,3); % average across 3rd dimension
Best, K.
##### 2 CommentsShowHide 1 older comment
Good points of course! All hail the allocation :)
Thanks for the supplements.

### Categories

Find more on Matrix Indexing 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!

Translated by