5ttgen hsvs template option

Dear experts,

I am upgrading my current connectome pipeline based on mrtrix’s newer release, thereby taking advantage of 5ttgen’s newer algorithm hsvs. Currently I am using fsl algorithm as follow:
5ttgen fsl freesurfer_brainmask.mgz 5TT.mif -premasked -nocrop -nthreads 35.

5ttgen hsvs provides an option to use a template image **-template** Provide an image that will form the template for the generated 5TT image. May you please explain a bit more about this option and advice what image should we use, apologizes in advance as I could not find more details about it anywhere in the doc? Currently, my DWI is registered to freesurfer space (yes memory overload, although I have changed my strides for continuous memory storage early on in my pre-processing steps), so I would expect my template to be in freesurfer space too right?

Thank you,
Sneha

Hi Sneha,

May you please explain a bit more about this option and advice what image should we use

The primary use of 5ttgen hsvs's -template option is to generate the 5TT image at a different spatial resolution to that of the FreeSurfer 1mm voxel grid. E.g. I’ve shown 5TT images at 0.5mm using this script. This could theoretically give more precise results in cases where different estimated surfaces are within a mm of one another, but I’ve not thoroughly evaluated the effect of such on tracking execution speed. I decided to provide this capability via the -template option rather than just setting the voxel size as it is a more general solution, e.g. this way one can define a template image where the axis orientations are different.

Currently, my DWI is registered to freesurfer space (yes memory overload, although I have changed my strides for continuous memory storage early on in my pre-processing steps), so I would expect my template to be in freesurfer space too right?

  1. Sorry to be draconian on language, but I presume that you mean that your DWI data have been re-gridded to FreeSurfer space? It’s possible to register DWI to T1, and transform DWI data to spatially overlap with the T1 image, without ever re-gridding / re-sampling the image data onto the higher-resolution voxel grid?

    We should write a Wiki entry on the differences between registration / transformation / re-gridding…

  2. 5ttgen is wholly agnostic of the DWI data and therefore can’t be based on the voxel grid of such. In the absence of the -template option, the output image is based on image aparc+aseg.mgz.

Rob

1 Like

The primary use of 5ttgen hsvs's -template option is to generate the 5TT image at a different spatial resolution to that of the FreeSurfer 1mm voxel grid.

Is this similar to what mrgrid achieves?

Sorry to be draconian on language, but I presume that you mean that your DWI data have been re-gridded to FreeSurfer space? It’s possible to register DWI to T1, and transform DWI data to spatially overlap with the T1 image, without ever re-gridding / re-sampling the image data onto the higher-resolution voxel grid?

While preprocessing DWI data I have used epi_reg outside of mrtrix for fieldmap correction (reason being that some of our data only have gradient field maps as phase/magnitude pair). In my understanding epi_reg does both transformation and resampling onto higher resolution freesurfer T1 image which I have used as a reference image, but please correct me if I am wrong. I had to tend to epi_reg given the limitation of our dataset for EPI distortion correction. I believe resampling it back to lower-resolution might involve add-on interpolation which would be better off avoided, but open to better solutions.

We should write a Wiki entry on the differences between registration / transformation / re-gridding…

I bet we do :grimacing:

5ttgen is wholly agnostic of the DWI data and therefore can’t be based on the voxel grid of such. In the absence of the -template option, the output image is based on image aparc+aseg.mgz .

Perfect, this is good to know as I was not able to find its default

Another related question I have is if 5ttgen hsvs can be used when we are using samseg routine instead of recon-all -all option?

Is this similar to what mrgrid achieves?

No. mrgrid would take image data stored on one voxel grid, and resample it onto a different voxel grid. Where the target voxel grid is of higher spatial resolution than the input, the result will be “blurry”. With 5ttgen hsvs, anything with a surface-based representation (whether native or intermediate) can be mapped to a partial volume image on any target voxel grid. So even if the target voxel grid is of absurdly high spatial resolution, the partial volume image will still be exceptionally sharp, reflecting the infinitessimally thin nature of the surface-based representation.

While preprocessing DWI data I have used epi_reg outside of mrtrix for fieldmap correction (reason being that some of our data only have gradient field maps as phase/magnitude pair). In my understanding epi_reg does both transformation and resampling onto higher resolution freesurfer T1 image which I have used as a reference image, but please correct me if I am wrong. I had to tend to epi_reg given the limitation of our dataset for EPI distortion correction. I believe resampling it back to lower-resolution might involve add-on interpolation which would be better off avoided, but open to better solutions.

While I’ve heard of epi_reg regularly I’m not familiar with its operation. If this is the case it’s probably more justification to finally get around to supporting field maps in dwifslpreproc; it just keeps getting bumped down the priority list because I don’t have any such data myself, so if anyone feels like getting their hands dirty with some Python please do…

Another related question I have is if 5ttgen hsvs can be used when we are using samseg routine instead of recon-all -all option?

If it doesn’t overwrite the standard FreeSurfer output files but instead creates its own with different names, then no, hsvs won’t identify them. I’d not heard of it until now, so I’d need to see what it produces and whether or not it can be used.

Hi Rob,

Thank you so much for your input.

If it doesn’t overwrite the standard FreeSurfer output files but instead creates its own with different names, then no, hsvs won’t identify them. I’d not heard of it until now, so I’d need to see what it produces and whether or not it can be used.

For now it does follow an independent but similar output files. It creates a separate output folder named samseg and saves all files created by this routine under it in addition to standard mri folder. I do have couple of subjects that I ran with this routine and can try running it and see if it proceeds without any error. It is packaged with their newer release and we tried it for its faster run time. Per their release notes:
“Sequence Adaptive Multimodal Segmentation (SAMSEG). This is a new tool that provides whole-head segmentation (like the aseg in the recon-all stream). It can operate on any modality or combination of modalities. It can run in cross-sectional and longitudinal modes. SAMSEG also has an advanced white matter lesion segmentation (cross-sectional only). The cross-sectional segmentation runs in about 45min single threaded.”

Thank you,
Sneha

Hi @rsmith ,

Thanks for this new 5TTgen method, its great!

I had a similar question about the -template option and how the registration to the template is calculated, and was wondering if it would be possible to specify the transform manually for a similar epi_reg application where fieldmaps have been used to correct for EPI distortion. I have noticed that the registration with the present method does not overlay precisely with the image which used fieldmap information to perform the coregistation.

This is what my workflow looks like, and @snp2003 is using some variation of it, as I understand (irrespective of resampling)

  1. Calculate EPI distortion and BBR of B0 to FreeSurfer anatomical using epi_reg --> save linear transform and distortion warp
  2. Apply distortion correction warp without moving the diffusion image using FSLs applywarp
  3. Convert linear transform from FSL format to MRtrix format using transformconvert
  4. Move FreeSurfer anatomical into diffusion space with mrtransform (no resampling) - using inverse of the calculated transform
    I would like to then perform 5TTgen hsvs with FreeSurfer output, but use epi_reg transform (MRtrix format) to make sure that the 5TT image matches perfectly with the diffusion volume.

This could be used more generally as well, if someone prefers to use another tool (ANTs for example) to perform the coregistration, and then pass it on to the algorithm…

Would this be feasible to do? I could help scripting this if given sufficient guidance :slight_smile:

Thanks in advance,
Nick

I had a similar question about the -template option and how the registration to the template is calculated, and was wondering if it would be possible to specify the transform manually for a similar epi_reg application where fieldmaps have been used to correct for EPI distortion.

I think there may be two separate concepts getting blurred together here.

For 5ttgen hsvs, there is zero image registration or transformation. All the -template option does is say, when you take the FreeSurfer surface data and map it to a partial volume image, rather than the voxel grid target being the FreeSurfer 1mm image, use this image instead.

I believe this may be contributing to the confusion:

I would like to then perform 5TTgen hsvs with FreeSurfer output, but use epi_reg transform (MRtrix format) to make sure that the 5TT image matches perfectly with the diffusion volume.

Unless you have some explicit justificatin for doing so, there is no need for the 5TT and DWI data to be defined on the same image grid. ACT was deliberately designed to allow for these two distinct sources of information to be defined on different voxel grids. That way, you’re not downsampling your anatomical image data and losing resolution, and you’re not needlessly upsampling your diffusion image data and increasing storage space / processing time.

Calculate EPI distortion and BBR of B0 to FreeSurfer anatomical using epi_reg --> save linear transform and distortion warp

I presume you mean b=0 rather than B0?

I’ve never actually used this tool myself so I can’t really comment on how best to use it.

Move FreeSurfer anatomical into diffusion space with mrtransform (no resampling) - using inverse of the calculated transform
I would like to then perform 5ttgen hsvs with FreeSurfer output, but use epi_reg transform (MRtrix format) to make sure that the 5TT image matches perfectly with the diffusion volume.

I think I may be failing to follow this with sufficient accuracy because of the ambiguity between linear and non-linear components of the transformation. My suggestion here (admittedly again naive to the details of epi_reg) would be that any non-linear component should ideally be dealt with in the context of DWI pre-processing, since these are geometric distortions in the DWIs for which correction must be beneficial. So the question then would be: is it possible to integrate this mode of EPI distortion correction into dwifslpreproc? This would involve converting the non-linear component of epi_reg's output into a field map that could be provided to eddy, so that correction of such can be done along with all other geometric corrections in a single interpolation step.

Dear @rsmith,

Thanks for the clarification, if I understand correctly, the -template option is only to specify the matrix for initializing the output image, and there is no attempt to coregister the 5ttgen hsvs output with the template. So if recon-all was performed on the non-coregistered anatomical image (not registered to the diffusion image), I would still need to coregister the 5ttgen hsvs output (whether or not the -template option is used) to the diffusion image.

Thanks,
Nick

if I understand correctly, the -template option is only to specify the matrix for initializing the output image

Correct: it’s purely for custom definition of the voxel grid upon which partial volumes are calculated.

there is no attempt to coregister the 5ttgen hsvs output with the template. So if recon-all was performed on the non-coregistered anatomical image (not registered to the diffusion image), I would still need to coregister the 5ttgen hsvs output (whether or not the -template option is used) to the diffusion image.

Adding link to the Wiki page on the terminology surrounding these concepts in case it’s a simple matter of word substitution; but I need to give the exhaustive answer anyway just in case.

You’re correct in that there is no form of image registration involved. Though it’s unclear to me what form this would even take. The output is a 4D image, and the image provided via the -template option doesn’t even need to contain any anatomy: it could contain all zeroes—hence being useless for image registration—and the hsvs algorithm would still work. A sufficiently large misalignment between the template image and the output of 5ttgen hsvs to lead to part of the brain being outside the FoV of the template image would imply that the selection of the template image was probably a bad one; but as long as the whole brain is inside the FoV of the voxel grid, there’s no possibility of “misalignment”, it’s just a specific voxel grid to which the tissue segmentaiton information is mapped.

Now if the template image does contain some anatomical information, and the 5ttgen output does not align with such, then this is not a 5ttgen issue, but an issue of the content of the template image not being spatially colocalised with the content of the anatomical image(s) provided as input to FreeSurfer, which is upstream.

In the case of your specific description—running FreeSurfer on a T1w image that is not registered with the diffusion image data—any registration that you have performed between T1w and DWI data yields as output a transformation that needs to be applied to one image or the other in order to make them align spatially. In the case of transforming T1w to DWI, you would simply take that linear transformation matrix and apply it to the 5ttgen hsvs output image. You would not want to “coregister” the 5ttgen output with the DWI data: apart from using a 4D image for registration (for which it’s unclear what the registration algorithm’s behaviour actually should be), you would then potentially have different spatial alignment to the DWIs between the 5TT image, and any other derivatives of the T1-weighted image.

Rob

Thanks Rob for the detailed response,

This is quite clear now!

Cheers,
Nick