How to determine median pixel intensity for each pixel from x number of pictures

3 views (last 30 days)
I am trying to do image processing and have a baseline composed of x number of images with the same dimensions.
I would like to create a single baseline image composed of the median pixel intensity of my baseline images.
I am relatively new to matlab and believe there must be a relatively easy way to do this operation. right now I am considering using a for loop to add pixel (1,1) for each individual picture append it to a list, find the median, add it to a new matrix and move on to pixel (1,2) this is obviously ineffecient and crude.
I would like an efficient script to determine the median pixel value of my each pixel pictures and create a new image composed.
Is there a way to compare the pixel intensity of each pixel for all of the images directly, doing the entire operation in one move?

Accepted Answer

Jon
Jon on 15 Oct 2020
Suppose your images are each in a mRow by nCol array and you have numImages total number of images. If you put all of the images into an mRow by nCol by numImages array, lets call it X then the baseline image would be given by
xBase = median(X,3)
  2 Comments
John Doe
John Doe on 19 Oct 2020
Thank you.
It took some time for me to work out since being new to matlab I didn't know about arrays, but this seems to have done the trick.
for n = 1:900
filename = sprintf('%s%03i%s', prefix, n, suffix);
pic_img = imread(filename); %load stimulation frame no n
img_array(:,:,n) = pic_img;
end
Median_pic = median(img_array,3);
imshow(Median_pic)
Jon
Jon on 26 Oct 2020
Hi, Looks good. I'm glad you were able to move ahead with this and are able to start figuring out how to do things in MATLAB. If you haven't done it already a good way to get a quick immersion in MATLAB is the MATLAB On Ramp https://www.mathworks.com/learn/tutorials/matlab-onramp.html

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!