Align mask with EPI image

I want to project the region of interest (ROIs) from [1] on my subjects’ surface and create a NIFTI file out of them. The ROIs are in 1d.dset format in AFNI. To do this, first, I mapped ROIs (e.g. v1_lh.1d.dset) on the subject surface (std.141.mysubj_lh.spec), which has been created in Freesurfer and converted to spec file using @SUMA_Make_Spec_FS, with the following command:

3dSurf2Vol -spec std.141.mysubj_lh.spec -surf_A lh.smoothwm -surf_B lh.pial -grid_parent mysubj_SurfVol.nii -sv mysubj_SurfVol.nii -map_func ave -f_steps 10 -f_index voxels -sdata_1D v1_lh.1d.dset -prefix v1_lh.nii.gz

The result was acceptable (figure below).

I want to align the NIFTI files from ROIs (e.g. v1_lh.nii.gz) with the EPI images. However, the structural image from @SUMA_Make_Spec_FS is not aligned with the EPI image. Would you please help me to align the masks (ROIs) with the EPI image?

  • One solution that comes to my mind is to align the structural image with the EPI image using Then use the transformation matrix form to align masks with the EPI image, but I do not know how to use the transformation matrix to transform the masks.

[1] Probabilistic Maps of Visual Topography in Human Cortex; Liang Wang, Ryan E B Mruczek, Michael J Arcaro, Sabine Kastner


A few ways to do this:

  1. Align your anatomical to the EPI dataset first, then redo Freesurfer processing using that anatomical dataset. Then repeat @SUMA_Make_Spec_FS, etc.

  2. Align EPI data to anatomical dataset as part of your processing with If you’re doing motion correction anyway, interpolation effects should be minimal.

  3. Align your anatomical to the EPI dataset using Then use that volume as the -sv volume option to align to experiment.

  4. Align your anatomical data to the EPI dataset using Transform the ROI data using the transformation computed with “3dAllineate -NN -1Dmatrix_apply” (using the transformation 1D file output from

Thank you, Daniel.
Item four worked for me. However, I used 3dresample after 3dAllineate, too. These are the commands I used: -anat brain.nii.gz -epi fmri.nii -epi_base 5 -volreg off -tshift off -anat_has_skull no -epi_strip None

3dSurf2Vol -spec std.141.brain.spec -surf_A smoothwm -surf_B pial -grid_parent brain.nii.gz -sv brain.nii.gz -map_func ave -f_steps 20 -f_index points -sdata_1D mask.1d.dset -prefix mask.nii.gz

3dAllineate -prefix align_mask.nii.gz -source mask.nii.gz -NN -1Dmatrix_apply brain_al_mat.aff12.1D

3dresample -master fmri.nii -prefix final_mask.nii.gz -input align_mask.nii.gz

Great. You can skip the resample step by specifying the -master dataset in 3dAllineate.

Thank you, Daniel.
I have a question. I checked the alignment of the mask and EPI images in ANFI and it seems that they are aligned, as in the figure below. However, when I checked them in ITK-SNAP, It seems that they are not aligned! Do you know why this is so?
I want to use the mask in CoSMoMVPA using cosmo_fmri_dataset and after checking the result with ITK-SNAP, I am not sure whether the mask and the EPI image are aligned are not.

For the both images:
Dimensions: 120x120x75
Voxel spacing: 1.75x1.75x1.75
Origin: -106.312x87.8681x-54.6848
for one of them:
Orientation: Oblique (Close to RPI)
and the other one:
Orientation: RPI

I think it’s likely this is an oblique dataset, and ITK-snap will show that differently than AFNI. You can remove the obliquity of copy of the dataset by doing this:

3dcopy mydset.nii.gz mydset_no_ob.nii.gz
3drefit -deoblique mydset_no_ob.nii.gz

Then view that dataset in ITK-snap with the same ROI data. In AFNI, you may want to save the dataset with a header attribute that will enforce a color map more suitable for ROIs with:
3drefit -cmap INT_CMAP myROIs.nii.gz

Thank you, Daniel.