warning while using 3dcalc to combine 2 masks


I am trying to use 3dcalc to combine 2 masks. I want a resulting mask that will only include the voxels which are in both input masks. But I am getting a warning saying

“*+ WARNING: Template space of dataset strcon_thr25_3_AD_TD_4_3_tr+tlrc. does not match space of first dataset”

This was the command I used:
3dcalc -a mask_AD_TD_4_3_trend+tlrc. -b strcon_thr25_3_AD_TD_4_3_tr+tlrc. -expr ‘step(a)+2*step(b)’ -prefix strcon_thr25_3_mask_AD_TD_4_3_trend

One of the masks I am combining is from my group contrast (using clust_mask) and the other one I got from FSL (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Atlases/striatumconn)

I tried using 3dwarp to convert it but the result looked like it had many decimal values, whereas the input had just had 3 values (1,2,3)
3dWarp -mni2tta -prefix converted-striatcon-thr50-3sub-2mm+tlrc. striatum-con-label-thr50-3sub-2mm.nii.gz

I also tried using 3dresample
3dresample -master mask_AD_TD_4_3_trend+tlrc. -input striatum-con-label-thr25-3sub-2mm+tlrc. -prefix strcon_thr25_3_AD_TD_4_3_tr

but I still get that original warning when I do 3dcalc. Can anyone help me figure out what I am doing wrong? Maybe many things :frowning:

Thanks so much for any help,


Hi, Prerona-

What is the output of:

3dinfo -av_space -space -d3 -orient -o3 -prefix mask_AD_TD_4_3_trend+tlrc. strcon_thr25_3_AD_TD_4_3_tr+tlrc.



Thank you. Here it is

/main_masks$ 3dinfo -av_space -space -d3 -orient -o3 -prefix mask_AD_TD_4_3_trend+tlrc. strcon_thr25_3_AD_TD_4_3_tr+tlrc.
+tlrc TLRC 2.000000 -2.000000 2.000000 RPI -90.000000 126.000000 -72.000000 mask_AD_TD_4_3_trend

sorry accidentally hit submit twice!

Hi, Prerona-

Well, I’m not sure why the second dset doesn’t appear to exist-- I had just tried to copy+paste the names from your 3dcalc command above, but perhaps they aren’t in the same directory or something?

Mainly, could you run the following before each of the two input files used in your 3dcalc command, and then report the output? i.e.:

3dinfo -av_space -space -d3 -orient -o3 -prefix [FILE NAMES]



I am so sorry - I made a mistake last time I executed it - I guess I was sleepy :slight_smile: Here is the correct output (I had changed the name of the 2nd mask to _resampled and forgot)

/main_masks$ 3dinfo -av_space -space -d3 -orient -o3 -prefix mask_AD_TD_4_3_trend+tlrc. strcon_thr25_3_resampled+tlrc.
+tlrc TLRC 2.000000 -2.000000 2.000000 RPI -90.000000 126.000000 -72.000000 mask_AD_TD_4_3_trend
+tlrc MNI 2.000000 -2.000000 2.000000 RPI -90.000000 126.000000 -72.000000 strcon_thr25_3_resampled

best wishes


Right, so the “space” part of the header doesn’t agree between the two-- one is TLRC, one is MNI. Which is correct for your data?

You could copy the “bad” dset, and then use

3drefit -space [new space name] [copied data set]

to change that header info. Please do copy the dset, so that you don’t lose the original-- this overwrites the dset.

That being said, it is a little odd that this difference occurred…


Thank you so much! I am sure your suggestion will fix the problem - I will try it right now. But I am curious to understand what I did wrong, if possible?

I think the source for the one of the files was MNI (it came from from FSL - https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Atlases/striatumconn)
The other one is derived from my AFNI group contrast (using clust_mask) so that is the one that is probably Talairach?

But I am confused that it is still showing like this because I tried to convert from MNI to Talairach before doing the 3dCalc using 3dresample (using the command -
3dresample -master mask_AD_TD_4_3_trend+tlrc. -input striatum-con-label-thr25-3sub-2mm+tlrc. -prefix strcon_thr25_3_AD_TD_4_3_tr) because I saw it suggested somewhere to try this. It would be great if you could give me any idea about this?

Thanks! I think this worked because after doing 3drefit I tried 3dinfo again and got this

3dinfo -av_space -space -d3 -orient -o3 -prefix mask_AD_TD_4_3_trend+tlrc. strcon_thr25_3_3drefit+tlrc.
+tlrc TLRC 2.000000 -2.000000 2.000000 RPI-90.000000 126.000000 -72.000000 mask_AD_TD_4_3_trend
+tlrc TLRC 2.000000 -2.000000 2.000000 RPI-90.000000 126.000000 -72.000000 strcon_thr25_3_3drefit

Hi Prerona,

We can look at this more tomorrow, but it does not seem quite right.

3dresample can change the grid, but it does not transform between
spaces. There may be a 3dWarp command to do that. So running
3drefit might be masking a real problem, in that the volumes really
are in different spaces, and they are not ready to be combined.

  • rick

Rick’s suggestion that 3dresample and 3drefit don’t actually change the space of a dataset except in the header is correct. A more complicated spatial transformation is needed - like alignment, application of an affine transformation or 12-piece transformation. See this previous post and the links there for more information.



thank you so much. I will go through these posts. I never realized there were variants of the spaces themselves! Since I got my mask from FSL probably I should be using one of the methods with MNI FSL transformation matrix you suggest here: https://afni.nimh.nih.gov/afni/community/board/read.php?1,70173,80922#msg-80922

But I also have one question - I was using the command 3dcalc and it was giving me a warning about space mismatch. After I did 3drefit this warning went away. Does this mean the space issue was correctly fixed by 3drefit?



3drefit is a program for changing header information. It is used when the header is incorrect, and needs to be adjusted. The space property is a designation that mainly affects properties of what can be associated with a dset (like an atlas). See more here:

Note that 3drefit behaves veeery differently than 3dresample, which can also adjust header information (as part of its functionality), but in this case the info is assumed to be correct to start with, and so it changes the property both in the header and in the data itself. For example, if you need to adjust the orientation of a dset you would use 3drefit if the existing orientation were wrong, and 3dresample if it were correct.


got it! Thank you so much