bug with 3dcalc?

Hello AFNI team,

I would like to create a left and right hemisphere atlas and add 1000 to the Right hemisphere.
atlas_L.nii.gz is the left hemisphere image.
atlas.nii.gz the entire atlas.

I first tried:


3dcalc -a  atlas_L.nii.gz -b atlas.nii.gz -expr "(b-a)+(step(b-a)*1000)" -prefix atlas_R.nii.gz

and it didn’t give me any logical result when:


3dcalc -a  atlas_L.nii.gz -b atlas.nii.gz -expr "(b-a)+(step(b-a)*100)" -prefix atlas_R.nii.gz

did

I am not sure I understand what is going on =)
Have a good Weekend Y’all

The atlas is probably a ‘byte’ dataset going from 0-255. So adding 1000 would not make sense.
Use 3dinfo to check the datum, and add “-datum short” to 3dcalc to convert it.

  • rick

And, separately, note that you can use ‘x’, ‘y’, ‘z’ and ‘t’ to represent spatial and temporal values, respectively, if you haven’t used those to load in a dset (as well as ‘i’, ‘j’, ‘k’ and ‘l’ for their index analogue). See here:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/programs/alpha/3dcalc_sphx.html#coordinates-and-predefined-values

One use here might be to use a full atlas on its own and add 1000 everywhere that the x coordinate is >0:


3dcalc -a atlas.nii.gz -expr "a+1000*a*ispositive(x)" -prefix atlas_adding_1000_to_half.nii.gz -datum short

… which could also be written:


3dcalc -a atlas.nii.gz -expr "a*(1+1000*ispositive(x))" -prefix atlas_adding_1000_to_half.nii.gz -datum short

If it is the negative coords that are on the right side of the brain (like in RAI-DICOM notation), then perhaps:


3dcalc -a atlas.nii.gz -expr "a*(1+1000*isnegative(x))" -prefix atlas_adding_1000_to_half.nii.gz -datum short

Deciding exactly where you want the boundary to be is an important consideration (everything >0, or everything >=0?) You can shift the boundary line algebraically, as needed:


3dcalc -a atlas.nii.gz -expr "a*(1+1000*isnegative(x-17))" -prefix atlas_adding_1000_to_half.nii.gz -datum short

–pt