Nonlinear coregistration with tagsets

Hi everybody
I’m working on 3d stacks of images of rat brains from confocal microscopy. I have to register them to an Allen standard template, so I’m testing AFNI on this.
I’m getting quite good results with 3dQwarp. Nonetheless, I need to further improve these results. I have a set of markers (or tagsets, as you call them in 3dTagalign) matching points in the atlas with points in the confocal images. Is there anyway I can integrate this information in a pipeline for nonlinear image coregistration?

PS: is plug_tag still available? I’d need a tool to insert custom markers in the header, setting attributes such as TAGSET_NUM, TAGSET_FLOATS. TAGSET_LABELS. I can not find the plug_tag tool tho.
I have been trying something like
3drefit -atrstring TAGSET_FLOATS “$x0 $y0 $z0 0 0 $x1 $y1 $z1 1 0” $dataset_name
but then the output of
3dAttribute TAGSET_FLOATS $dataset_name
is empty


Unlike 3dTagalign for affine alignment, 3dQwarp does not provide for tags in the alignment directly; however, you can be target particular locations. One way is to increase the weights at target points with the -weight option or the weight-enhancing options of -wball and -wmask. Besides that, you can also change the penalty factors with -penfac or -nopenalty to allow for bending in the warp.

Which Allen template are you using, and what is the use case here?

Hi, thanks for the kind reply
I’m trying to coregister images acquired with confocal microscopy with 25 micron isotropic resolution to the NISSL coronal Allen brain atlas ( obtained by converting to nifti a stack of tiff. As I said, results are almost satisfying, in particular for what regards outer edges, while there is still space for improvement in inner edges, maybe also due to the different contrast.
I will try to use the weights and penalty factors and keep you updated, thanks.
Meanwhile, is there any way you can help me with adding markers in the dataset header?
As mentioned, I tried with
3drefit -atrstring TAGSET_FLOATS “x0 y0 z0 0 0 x1 y1 z1 1 0 x2…” dataset_name
but it does not seem to work.
I would like to try to alternate stages of 3dQWarp with stages of 3dTagalign, but to do that, I have to be able to provide the tagsets to 3dTagalign

Thank you

You can subdivide your output for particular regions of interest. The most obvious way to create tags is with the Tagset plugin. You can mark the tags there or read the tags from a file with this format below. The attribute in the header gets updated from that.

# Label_   _____x_____ _____y_____ _____z_____ ____val____ _t_
'AC'             0.125      -30.25       22.75           1   0
'PC'             0.125        -6.5        13.5           2   0
'CP'             0.125        -0.5          10           3   0

Multiple alignments would introduce multiple interpolations that may be more important to you. You can combine affine and nonlinear warps with 3dNwarpCat or with 3dNwarpApply.

Did you use the Slicer nrrd format here for the Allen mouse brain?

The units are in um there, and the coordinate system is funky on the latest version. You can try the versions we have here (2012, 2017):

In past work with similar microscopy data and this template, you will need to take into account the large amount of data and memory limits. Downsampling the data can help, depending on the needed final resolution. Also depending on the type of histology you are doing, you may want different kinds of alignment cost functions or blurring/feature sizes in the alignment process. I’ve used these commands for alignment with good results.

align data to Allen mouse template with affine transformation -cost lpa+ZZ -dset1 channel0_0.025_center2017.nii.gz -dset2 allen_50u_dgtest_to3d+orig.
-overwrite -suffix _al2allen2017_c -dset1_strip None -dset2_strip None
-Allineate_opts ‘-source_automask+4 -twoblur 0.500000 -blok “RHDD(0.200000)”
-twobest 11 -twopass -VERB -maxrot 10 -maxshf 5 -maxscl 1.5 -fineblur 0.2 -source_automask+2’

nonlinear alignment

3dQwarp -base allen_50u_dgtest_to3d+orig. -source channel0_0.025_center2017_al2allen2017_c+orig.
-prefix channel0_0.025_qw3 -workhard “0:2” -saveall -resample -lpa -maxlev 11

If you want, PM or email me for details.

Thank you so much for the detailed reply.
I managed to save the tags in the .HEAD using the plugin.
The 3dQwarp command I was testing is quite similar to the one you suggested, I only have to further test the workhard option. Using the option -iniwarp and always the same image as source I guess that I will have no problems of resampling.
Two more questions:

  • I tested 3dTagalign: how is this program working? Is it matching tags by label? I have for both datasets a set of tags with the same labels, but sometimes tags are close to each other, so I was wondering if the matching is computed between labels pairs.
  • I see that after warping a dataset with 3dQwarp, the tags in the header disappear. Is there a way to obtain a new warped dataset with updated tags in the header? Or should I find a way to apply the warp to the markers externally, and then use again the plugin to assign them to the new header?
    (is there a 3dNwarpApply function for vectors??)

Thank you

That all sounds good. I’ve recently been moving markers around too, and I’m happy to send that script if you would like. There is 3dNwarpXYZ for coordinates that you could apply to tag coordinates. Provide an xyz.1D file with 3 columns of coordinates in RAI order (Right-to-left, Anterior-to-posterior, Inferior-to-superior).

3dNwarpXYZ -nwarp “$WARP” -iwarp ${src_name}_xyz.1D > ${src_name}to${target_name}_xyz.1D

As part of my script, I also put spheres at the source and target locations because I find that’s useful for visualization, but the crosshair markers are fine too. Some examples of the spheres are here:

3dTagalign requires the order match exactly. Labels are a convenience. The method works by finding a least squares solution. This information is excerpted from the source, thd_shear3d.c, DLSQ_affine() function:

Compute an affine transformation to take one set of vectors into another.
That is, find general matrix R and vector V so that

 yy = [R] xx + V   (k=0..n-1)
   k        k

is true in the unweighted least squares sense.

Wow, 3dNwarpXYZ is exactly what I was looking for, thank you, I couldn’t find it. I’ll work on it, but yes of course, I would be happy to have that script!
Thank you for the excellent support

PS: now I have all the tools, but of course a scriptable way to insert markers in the header would be awesome.
Is there any news on the plug_tag.c function? Or maybe some way to use the tagset.h file?


All good news! Did you get to see the script I sent?

Yes, thank you very much for the script. I wanted to reply to you when I had some news or questions, but unfortunately this is a side project on which I don’t work full time, and I still have some tests to do. I will update you probably next week.