Filter löschen
Filter löschen

find the average pixel value of matrix of images

16 Ansichten (letzte 30 Tage)
michael bowen
michael bowen am 17 Dez. 2021
Kommentiert: Konrad am 17 Dez. 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);
allImages{i} = imread(outputFileName);
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

Antworten (1)

Konrad
Konrad am 17 Dez. 2021
Bearbeitet: Konrad am 17 Dez. 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 Kommentare
Image Analyst
Image Analyst am 17 Dez. 2021
You left out the allocation and some other robustness
numImages = 10;
allImages = zeros(1080, 1920, numImages, 'uint8'); % HDTV resolution -- 1080 lines (rows)
counter = 1;
for k = 1 : numImages
outputFileName = sprintf('bwImage%d.jpg', k);
fprintf('Reading in %s.\n', outputFileName);
if isfile(outputFileName)
allImages(:, :, counter) = imread(outputFileName); % concatenate images in 3rd dimension
counter = counter + 1;
else
message = sprintf('File not found : ', outputFileName)
uiwait(warndlg(message));
end
end
% Crop if some images were missing.
if counter < numImages + 1
allImages = allImages(:, :, 1:counter);
end
% Compute mean over all images of those images that we were able to read in.
meanImage = mean(allImages, 3); % average across 3rd dimension
% Display the image.
imshow(meanImage, []);
Konrad
Konrad am 17 Dez. 2021
Good points of course! All hail the allocation :)
Thanks for the supplements.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Install Products finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by