Hi everyone, sorry for the very basic question but I am fairly new to the world of neuroimaging in python.
I am using nilearn to build a couple of custom functions for my personal use, and I cannot find out how one can perform mathematical operation on multiple images on the 4th dimension.
I will try to explain me better with an example.
I have a list of filename called list_of_files
, I can open all the files in list_of_files
using imgs = image.load_img(list_of_files)
. Now, I can binarize all the images at once with something like bin_imgs = image.math_img('img > 1', img = imgs)
and then obtain the mean value in all voxels over all images with freq = image.mean_img(bin_imgs)
.
However, let’s say that I want to sum values at each voxels over all images and then divide it for some number, how could I do it ? If I try something on the line arbitrary_operation_over_time = image.math_img('sum(img)/10', img = imgs)
and plot the resulting image, it is quite evident that this does not work. I could go for something like image.math_img("(img1 + img2 + img3)/10", img1 = one_image, img2 = another_image, img3 = a_third_image)
but I am looking for a solution which will work for an arbitrary number of images.
Any tip is appreciated
Federico