extract mask for BOLD images from anatomic image mask

Hi,

I am a statistician: please pardon the naivette in asking this question but I am trying to use AFNI to massage my functional data in anatomic space.

I have an anatomic mask in registered space of the following dimensions, according to 3dinfo:


$ 3dinfo highres001_brain_mask.nii.gz 
++ 3dinfo: AFNI version=AFNI_16.2.18 (Sep 19 2016) [64-bit]

Dataset File:    highres001_brain_mask.nii.gz
Identifier Code: NII_leRqPU-x38xngCWArCInPg  Creation Date: Tue Feb  6 15:42:38 2018
Template Space:  ORIG
Dataset Type:    Anat Bucket (-abuc)
Byte Order:      LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode:    NIFTI
Storage Space:   21,233,664 (21 million [mega]) bytes
Geometry String: "MATRIX(1.2,0,-4.44089e-16,-87.57317,1.110223e-16,-1.197917,1.785035e-08,86.66275,2.220446e-16,-4.15611e-18,1.197917,-113.6052):144,192,192"
Data Axes Tilt:  Plumb
Data Axes Orientation:
  first  (x) = Right-to-Left
  second (y) = Posterior-to-Anterior
  third  (z) = Inferior-to-Superior   [-orient RPI]
R-to-L extent:   -87.573 [R] -to-    84.027 [L] -step-     1.200 mm [144 voxels]
A-to-P extent:  -142.139 [A] -to-    86.663 [P] -step-     1.198 mm [192 voxels]
I-to-S extent:  -113.605 [I] -to-   115.197 [S] -step-     1.198 mm [192 voxels]
Number of values stored at each pixel = 1
  -- At sub-brick #0 '?' datum type is float

I would like to use the mask on the functional image which has the following dimensions:


$ 3dinfo  bold.nii.gz 
++ 3dinfo: AFNI version=AFNI_16.2.18 (Sep 19 2016) [64-bit]
*+ WARNING: NO spatial transform (neither qform nor sform), in NIfTI file 'bold.nii.gz'

Dataset File:    bold.nii.gz
Identifier Code: NII_JyK_cBH0zg63lAZEiCCJPw  Creation Date: Tue Feb  6 15:43:46 2018
Template Space:  ORIG
Dataset Type:    Echo Planar (-epan)
Byte Order:      LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode:    NIFTI
Storage Space:   66,811,392 (67 million [mega]) bytes
Geometry String: "MATRIX(1,0,0,0,0,1,0,0,0,0,1,0):72,72,36"
Data Axes Tilt:  Plumb
Data Axes Orientation:
  first  (x) = Left-to-Right
  second (y) = Posterior-to-Anterior
  third  (z) = Inferior-to-Superior   [-orient LPI]
R-to-L extent:   -71.000 [R] -to-     0.000     -step-     1.000 mm [ 72 voxels]
A-to-P extent:   -71.000 [A] -to-     0.000     -step-     1.000 mm [ 72 voxels]
I-to-S extent:     0.000     -to-    35.000 [S] -step-     1.000 mm [ 36 voxels]
Number of time steps = 358  Time step = 1.00000s  Origin = 0.00000s
  -- At sub-brick #0 '?' datum type is byte
  -- At sub-brick #1 '?' datum type is byte
  -- At sub-brick #2 '?' datum type is byte
** For info on all 358 sub-bricks, use '3dinfo -verb' **

Is there a way to essentially refit the mask to match the dimensions in the BOLD space?

Feel free to let me know if my question is unclear.

Many thanks again for any help, and best wishes,
Ranjan

3dresample and 3dfractionize have two approaches to doing this. The first interpolates the mask onto the output grid using different interpolation schemes. For masks, you will want to use the NN (nearest-neighbor) method. 3dfractionize allows a little more flexibility by allowing the resampling to include voxels that aren’t partially filled or filled with different regions. One can pick the fraction to preserve the original value. See the help for each of these program or the afni11_roi.pdf class documentation for more details.

https://afni.nimh.nih.gov/pub/dist/edu/latest/afni_handouts/afni11_roi.pdf

That EPI dataset looks kind of small (in space). Only 71 mm in extent from L-R (half the brain width, roughly) and also in A-P, and only 35 mm in I-S. If you look at these two datasets in AFNI, do they properly overlap? That is, if the EPI dataset is the underlay and the brain mask dataset is the overlay, do the images overlap properly?

RWCox Wrote:

That EPI dataset looks kind of small (in space).
Only 71 mm in extent from L-R (half the brain
width, roughly) and also in A-P, and only 35 mm in
I-S. If you look at these two datasets in AFNI, do
they properly overlap? That is, if the EPI
dataset is the underlay and the brain mask dataset
is the overlay, do the images overlap properly?

Thank you very much. I have not tried to look into AFNI yet but will be doing so.
Btw, the False Beliefs Task where the datasets are supposed to have been uploaded after processing. I just assumed that they were okay.

Many thanks again!
Ranjan

I see – you are new to AFNI.

Always look at the data. Just because a data was put on a Web repository doesn’t mean it is OK. We have seen things where images were oriented incorrectly, “skull stripped” images still had the skull on, and so forth. AFNI is good for looking at 3D datasets.

Bob Cox Wrote:

I see – you are new to AFNI.

Always look at the data. Just because a data was
put on a Web repository doesn’t mean it is OK. We
have seen things where images were oriented
incorrectly, “skull stripped” images still had the
skull on, and so forth. AFNI is good for looking
at 3D datasets.

Thank you very much! I will look into it and let you know. I thought that these openfmri were careful about their datasets, but perhaps not.

Because we have seen some of the issues Bob mentioned specifically in the OpenFMRI dataset, I took a quick look at the linked data. If I use 3dinfo on this (see below), the voxels are 3x3x3.5mm, somewhat typical for fMRI; I don’t see the 1x1x1mm data you have, so something else happened to your data. There are a few more problems to look out for on this data, however. You will notice the BOLD datasets are acquired with two different orientations, RAI or RPI. I think the same orientation is used within subject for both BOLD runs, but this could lead to problems at the group level analysis if you assume the same grid, so you will have to be careful about that. In the BOLD data, the qform_code and sform_code values are set to 1 and 2, respectively. AFNI, by default, treats these as “tlrc” view, assuming these have been registered to a standard space. That makes it a bit tricky to view the BOLD data over the anatomical data. Set the AFNI environment variable, AFNI_NIFTI_VIEW, to orig in the shell or in your .afnirc file.

The anatomical data is slightly oblique at 3.5 degrees, but our standard processing should handle that. Additionally, the anatomical data varies in its resolution across subjects. Most, but not all subjects, have voxel sizes around 1.2mm. Orientations of those datasets are again surprisingly varied though with orientation orders of RPI and ASR. I’m not sure if that will affect your processing, but something else to keep in mind as you go.

openfmri/ds000109_R2.0.2] glend% 3dinfo -prefix -orient -d3 -o3 sub*/func/*.nii.gz
** AFNI converts NIFTI_datatype=512 (UINT16) in file sub-01/func/sub-01_task-theoryofmindwithmanualresponse_run-01_bold.nii.gz to FLOAT32
Warnings of this type will be muted for this session.
Set AFNI_NIFTI_TYPE_WARN to YES to see them all, NO to see none.
sub-01_task-theoryofmindwithmanualresponse_run-01_bold.nii.gz RAI 3.000000 3.000000 3.539701 -113.395279 -136.387894 -35.929810
sub-01_task-theoryofmindwithmanualresponse_run-02_bold.nii.gz RAI 3.000000 3.000000 3.539701 -113.786499 -136.681213 -34.904900
sub-02_task-theoryofmindwithmanualresponse_run-01_bold.nii.gz RAI 3.000000 3.000000 3.539928 -86.994926 -165.123245 -36.951183
sub-02_task-theoryofmindwithmanualresponse_run-02_bold.nii.gz RAI 3.000000 3.000000 3.539928 -87.875198 -163.503479 -41.624382
sub-03_task-theoryofmindwithmanualresponse_run-01_bold.nii.gz RPI 3.000000 -3.000000 3.539913 -110.812683 66.151535 -40.571239
sub-03_task-theoryofmindwithmanualresponse_run-02_bold.nii.gz RPI 3.000000 -3.000000 3.539913 -110.701958 66.595985 -40.198555
sub-05_task-theoryofmindwithmanualresponse_run-01_bold.nii.gz RPI 3.000000 -3.000000 3.539997 -103.874046 64.358917 -71.371323
sub-05_task-theoryofmindwithmanualresponse_run-02_bold.nii.gz RPI 3.000000 -3.000000 3.539997 -100.284164 66.343353 -64.523521
sub-07_task-theoryofmindwithmanualresponse_run-01_bold.nii.gz RPI 3.000000 -3.000000 3.540012 -121.250893 47.643005 -61.460804
sub-07_task-theoryofmindwithmanualresponse_run-02_bold.nii.gz RPI 3.000000 -3.000000 3.540012 -121.338051 48.233105 -61.566978