how to divide each voxel in a 3d dataset by one number which is written to a file

Hello afni experts,

I have a simple question here.
I have for each subject a 3D dataset which is one sub brick that contains only the beta coefficients for each voxel. I need to normalize those coefficients by a reference value which is the averaged signal across all functional volumes and voxels of each subject. (I am following a suggested pipeline to calculate a cerebro vascular reactivity index for each voxel). For each subject I have a .1D file which contains one number. (this number is different for each subject). What function can I use to divide each voxel in my sub brick dataset by this number?

I tried 3dcalc but it can only do voxel by voxel operations so it complains when I include as second input dataset which is not a 3d dataset

3dcalc -a betaCoefficients.nii.gz -b referneceValue.1D -expr ‘a/b’ >normalized betas.nii.gz

Thank you very much for any suggestions!

You do not need the -b variable:

for bash: 3dcalc -a betaCoefficients.nii.gz -b -expr ‘a/$( cat referneceValue.1D)’ >normalized betas.nii.gz
for tcsh or bash: 3dcalc -a betaCoefficients.nii.gz -b -expr ‘a/cat referneceValue.1D’ >normalized betas.nii.gz

This assumes that there is one and only one properly formatted number in referneceValue.1D

Thanks, Colm.

I think those quotes need to be double, so that what they encompass is still (partially) processed by the shell. As in:

for bash/zsh: 3dcalc -a betaCoefficients.nii.gz -b -expr “a/$( cat referneceValue.1D)” -prefix normalized betas.nii.gz
for tcsh: 3dcalc -a betaCoefficients.nii.gz -b -expr “a/cat referneceValue.1D” -prefix normalized betas.nii.gz

It might be clear to first set a variable to be the value from the text file, and then use it in 3dcalc.

bash:   val=$(cat referneceValue.txt)
tcsh:   set val = `cat referneceValue.txt`

3dcalc -a betaCoefficients.nii.gz -b -expr "a/$val" -prefix normalized betas.nii.gz
  • rick

Thank you very much for your help guys!
I think the -b did not belong there. Once I removed it it worked !

Thank you very much :))