Adding sub-briks together without dividing


It is my goal to add all 124 sub-briks from a dataset into one grand-sum 3D file. Is there a more efficient way to do this than 3dcalc -a data[0] -b data[1]… ? Is there some way to specify the n that I want to divide by for 3dmean? As of right now it automatically assumes the divisor to be 124 obviously. Any ideas?? If not, I’ve never used 3dcalc beyond -z, once it loops back around does it become -aa, -ab …?

Additionally, I tried 3dMean -sum, but this does not work as it adds together all the input datasets, not the sub-briks within a dataset, so the output for me (for one dataset) is the same as the input.


Hi, Mikey-

Yes, please don’t use 3dcalc for this… yikes!

If you are asking about taking one input 4D dataset called DSET_4D and calculate the sum across the 4th dimension (=time), then you can use:

3dTstat -sum -prefix dset_sum.nii.gz DSET_4D

For future reference, this program has lots of options for calculating voxelwise quantities across time.

Then you can use 3dcalc to divide the result by whatever you want, such as with this unlikely candidate:

3dcalc -a dset_sum.nii.gz -expr 'a/3.14159' -prefix dset_sum_div_pi.nii.gz

And indeed, if your question was to perform voxelwise addition over a set of 3D datasets, you could use the following:

3dmean -sum -prefix all_sum.nii.gz  DSET1 DSET2 DSET3 ....


I tried that out and for some reason it isn’t working, though logically everything seems like the right move. It is performing voxelwise addition right? So voxel x1, y1, z1 from each of my 120 sub-briks should be added together? When I look at the results this does not seem to be the case, as my output files have extremely small values at each voxel (0.0000x), despite the input sub-briks being z-scored, with values ranging from 0 to ±4.


Can you please post your exact command?

Also, can you please post the result of:

3dinfo -dmin -dmax -prefix [list of all dsets]

Well, if you don’t want to post the dset names, you could just post the result of:

3dinfo -dmin -dmax [list of all dsets]


ps: I also meant to note that there is an “-abssum” option in 3dTstat, if you want the sum of the absolute values of data values.