fMRIPrep coregistration within sessions?

Hi all,

I have a dataset with two fMRI sessions collected several hours apart. Each session contains multiple runs. From my understanding, fmriprep registers all bold files from all runs and sessions to the same T1 (which in this case was collected only in the first session). I’m wondering if it’s possible to first register the bold images within session, before registering to the T1? I would like to use RSA to compare activity from the first to the second session, so it’s important that they are well-aligned.

Thanks!

1 Like

Hi @cpauley, this isn’t currently possible.

You could hack around it by creating a fake sbref file for each BOLD series that will preempt our attempt to create a series-specific reference image. If you provide the same sbref for each BOLD series in a session, then that should achieve the goal you’re aiming at.

Hi @effigies,

How would you recommend creating this fake sbref file? The data was acquired using a multiband sequence.

Thanks!

I am also interested in this. If @effigies or @oesteban could suggest how to create this fake sbref file that would be highly appreciated.
Thanks!

Ah, right. Thanks for bumping this topic. If you would like to use our reference images, then probably the easiest approach is to install niworkflows:

pip install niworkflows

This will also install nipype, which will provide nipypecli, which we can use to run the tool that estimates reference images:

nipypecli run niworkflows.interfaces.registration EstimateReferenceImage /path/to/bold.nii.gz

You’ll get output like the following:

200203-11:21:53,787 nipype.utils INFO:
	 No new version available.
setting function inputs

in_file = /path/to/bold.nii.gz
mc_method = AFNI
sbref_file = <undefined>


n_volumes_to_discard = 1
ref_image = <pwd>/ref_bold.nii.gz

That last line shows you where the reference image was saved. You’ll probably want to save it to a new name that references the run it came from, so you don’t lose track.

Once you have a list of those, I would inspect each to make sure it looks reasonable, discard any that you don’t like, and construct a template with mri_robust_template (from FreeSurfer):

mri_robust_template --mov ref1.nii.gz ref2.nii.gz ... \
    --template ref.nii.gz --satit

You can use any other tool you like, but mri_robust_template has nice properties of discounting outlier voxels and constructing a template that’s approximately equidistant from each of the inputs, to reduce bias.

The result can now be copied to your BIDS directory as sub-XX/ses-YY/sub-XX_ses-YY_task-TASK_run-Z_sbref.nii.gz. You’ll need a copy for each BOLD file that you want to be registered using that as the reference.


Note that this may be sensitive to large changes in head position between runs. sbrefs are typically acquired immediately before a multiband run, so the offset should be minimal, and our head-motion-correction algorithms may assume that.


Note also that fMRIPrep will not know about this hack, and you’ll need to adjust any methods reporting to cover this. If you’re going to share your data, I would also suggest that you share these derived images and a script to produce them in your <bids-root>/derivatives directory, so that others can reproduce your work.

I am interested in using this method (submitting the same sbref file for each run) to align across sessions. But I also saw this Avoiding sbrefs for the coregistration reference causes poor registration in low contrast multiband sequences · Issue #3056 · nipreps/fmriprep · GitHub where it looks like sbrefs are not being used for co-registration.

Does that mean an attempt to use a fake sbref file won’t work?

meant to tag @effigies

Hi @effigies ,

I was wondering if and how this hack (supplying a single fake sbref to each of the runs) would interact with fieldmaps and multiple sessions.

Some details on my study: I have 2 sessions per subject, 8 runs per session (16 total), and 1 set of AP/PA pepolar fieldmaps per session (2 total). Originally my plan was to implement the single fake sbref hack (for example with the sbref of the first run of the first session duplicated for all 16 runs).

However, I noticed in the fmriprep results report that SDC is applied to the sbrefs as well. Now I’m worried that – while this would not affect session 1, where the fake sbref originates – fmriprep might apply the fieldmap acquired in session 2 to the fake sbrefs for all the session 2 runs. (As it wouldn’t know of this hack.) But those sbrefs were really acquired in session 1, so should probably have SDC applied using the fieldmap from session 1, not session 2.
I’m guessing this potential problem would be amplified when creating a mean sbref from all sbrefs from all sessions, as neither fieldmap would fully fit this mean image?

Is there a fault in my thinking (I hope so!) or would this be a reason not to apply this hack when preprocessing data from multiple sessions and applying SDC? What would be potential consequences?

Alternatively: Is there a way to use the IntendedFor / B0FieldSource for the sbrefs to point them to the 1st session’s fieldmap, even when their corresponding bold runs would still point to the 2nd session’s fieldmap?

Many thanks,
Jonathan

The proposal above was to use a common registration frame for each session, not a common registration frame across all sessions.

That said, this feels like an empirical question. The distortion-corrected sbref is used for registration, but it is not a useful output in itself. As long as the head motion parameters target the fake sbref and the alignment of the fieldmap reference and the sbref is good, then the fieldmap-estimated shifts should be correctly applied to each voxel in the BOLD time series. I would give it a try and see how it goes. The reports should give a first pass indication of whether things went well or poorly, and you can step through the output BOLD time series to observe the results.

Thanks for the quick response! If I understand correctly, the fieldmap reference is based on the anatomical and would therefore be identical for each of the 2 fieldmaps I’m recording? (I record 1 T1w in session 1, none in session 2.)

So this requirement should then be fulfilled, using otherwise standard fmriprep settings, right?

I see, so if there were any issues, they would more likely be with co-registration of the 2nd session, rather than with SDC?
So the primary output to check in the reports would be the one on “Alignment of functional and anatomical MRI data (coregistration)”, rather than the ones on SDC and alignment of SDC & “Alignment between the anatomical reference of the fieldmap and the target EPI”?

I unfortunately have yet to collect the 2nd session of pilot data, so can’t report any results just yet.

P.S.: The above aside, more of a conceptual question: It seems I misunderstood the original question in this thread, thinking it was about alignment across sessions. I also want to perform RSA comparing activity between two sessions (within-subject). I originally planned to do parts of the analysis in native EPI space and intended to use the sbref hack mostly for that, given that I thought – perhaps incorrectly – that this would not actually matter after coregistration to T1w space. I assumed that coregistering (to any space) would essentially align images within that space, making it possible to compare between sessions.
How does the alignment pre-coregistration affect alignment post-coregistration (in T1w (or potentially MNI) space)?
Would you consider it necessary to use the sbref hack at all? And if so, would you think it’s sufficient to use it as @cpauley intended (which I had previously misinterpreted) only within session, before coregistering to T1?

Many thanks!

For pepolar fieldmaps, the reference is actually the mean image estimated by TOPUP. In the future, I would like to select as the reference the EPI image that matches the polarity of the BOLD/SBREF file to be corrected, but this works well enough most of the time.

Yes.

Yes. A bad registration of a fieldmap to a BOLD volume would mean performing a warp where the expected signal sources and targets do not correspond to the right locations in the input image. You should be able to see evidence of this in the first two plots for a functional image, in fMRIPrep 23.2, at least.

You really should look at all of it. First, you want to look at the fieldmap report to see that the blue/red distortion blobs show up in reasonable places relative to the brain. (If this isn’t something you have experience with yet, they should at least be ~left/right symmetric in AP images, and focused near the frontal and temporal poles.) Then you want to look at the fieldmap reference-to-BOLD reference registration. It would also be good to look at the fieldmap correction before/after; if you’re not using precisely applicable BOLD inputs, you would expect a little bit of suboptimal correction but you shouldn’t see induced distortion. The coregistration report should clearly line up, though there will be sections where dropout and distortion do not fully recover anatomical fidelity in the BOLD image.

If you want to do things in native EPI space and for that to be a single space within each session, then the sbref hack makes sense (and use --output-space bold). If you’re going to be comparing across sessions, you can use the hack, but I would use fake sbrefs from both sessions to find a space that’s equidistant from both sessions; that way you aren’t inducing more resampling artifacts in one than the other. It’s probably simplest just to target the T1w space, though.

The effect should be pretty small.

1 Like

Thank you for the detailed explanation, this clarifies a lot of things for me!
And thanks also for the primer on how to use the fieldmap reports, this helps a lot! (no experience with fieldmaps on my side so far.)

Okay, then I think I might just stick with T1w space for now. But definitely keeping this in mind if I ever really want to do things in native EPI space.