MATLAB: Pixel means from a batch of images

meanpixel location

Hi,
Can someone tell me how I would go about getting the mean of the same pixel in a batch of 204 images? As it is now I can get the mean of the whole image(s), but I would like to choose a certain pixel location and have it go through the batch and get the mean for all of those pixels of the same location. Any help will be greatly appreciated.
Thanks

Best Answer

Sum up the images, and divide by the number of images. This will be another image and you can get the value at any pixel simply by indexing into that average image. Here's a snippet of code from a button callback that sums up the images that were selected in a listbox.
% Get a list of all the filenames.
ListOfImageNames = get(handles.lstImageList, 'string');
% Get a list of what files they selected.
selectedItems = get(handles.lstImageList, 'value');
% If none or only 1 are selected, use them all.
numberOfSelectedImages = length(selectedItems);
if numberOfSelectedImages <= 1
numberOfSelectedImages = length(ListOfImageNames);
selectedItems = 1 : numberOfSelectedImages;
end
% Get a list of the selected files only.
% Warning: This will not include folders so we will have to prepend the folder.
ListOfImageNames = ListOfImageNames(selectedItems);
caption = sprintf('Please wait...Constructing sum of %d images...', numberOfSelectedImages);
title(caption, 'FontSize', 20);
set(handles.txtInfo, 'string', caption);
drawnow;
for k = 1 : numberOfSelectedImages % Loop though all selected indexes.
% Get the filename for this selected index.
baseImageFileName = cell2mat(ListOfImageNames(k));
imageFullFileName = fullfile(handles.ImageFolder, baseImageFileName);
% Read and display the image.
imageArray = imread(imageFullFileName);
axes(handles.axesImage);
% Clear out the axes, otherwise it gets slower and slower each time you run it.
axes(handles.axesImage);
cla reset;
imshow(imageArray);
% Replace underlines with "backslash underline" otherwise the character following the underline will turn into a subscript.
caption = strrep(caption, '_', '\_');
title(caption, 'FontSize', 20);
set(handles.txtInfo, 'string', caption);
caption = sprintf('Displaying single image\n%s', baseImageFileName);
drawnow;
if k == 1
sumImage = int32(imageArray);
else
sumImage = sumImage + int32(imageArray);
end
end
averageImage = uint8(sumImage / numberOfSelectedImages);
% Display the final summed image.
axes(handles.axesImage);
imshow(averageImage, []);
axis on; % Show tick marks
caption = sprintf('Displaying average of %d images.', numberOfSelectedImages);
title(caption, 'FontSize', 20);