Home > other >  Calculate the sum of pixel intensities for each timepoint of array (python)
Calculate the sum of pixel intensities for each timepoint of array (python)

Time:06-20

I have a 3D array with the dimensions (141, 2048, 2048) where the first dimension is time. I would like to calculate the sum of values that are present in the 2048x 2048 array (pixel intensities) for each of the 141 timepoints and then plot it.

I tried it like this but it did not work for me. Can anyone help?

from skimage import io

bg = io.imread('myfile.tif')

y1 = []
for i in range(bg.shape[0]):
    y1.append(bg[i,:,:].sum)

CodePudding user response:

You can use the axis argument of sum with a tuple to sum over each image:

y1 = bg.sum(axis=(1,2))

Edit: The reason your original didn't work is because you used .sum instead of .sum()

  • Related