users > Failed to register one plane's calcium imaging trace onto template
Showing 1-5 of 5 posts
Display:
Results per page:
Jan 21, 2021  11:01 AM | Yuxin Tong - HKUST
Failed to register one plane's calcium imaging trace onto template
Hello everyone,

I am currently trying to register our lab's 2 photon imaging data of zebrafish larve onto a template.
My template is iteratively averaged by 10 z brain stacks on cmtk.
The objective is to register our experiment's calcium imaging activity time series(should be 1-6 planes) onto the template, so my current pipeline consists 3 steps: 
1. register calcium imaging activity experiment recording(1-6 planes, now i only tried 1 plane) onto same fish's z stack.(z stack is acquired right after the experiment recording)
2. register this fish's z stack onto template
3. apply two transformations file on experiment recording and get registered recording

Now the 2nd step I got good result but 1st and 3rd step failed.

Take one registration as example to elaborate, my z stack(zstack_fish1.nii) and template(template.nii) file size are both 1024x1024x101, there are 101 z planes from top to bottom of fish. My experiment recording file(movie_fish1.nii, format converted by figi) size is 1024x1024x924, 924 means it have 924 timepoints. It is a recording of one z plane roughly located between 39th-41th z plane of zstack_fish1.nii file. These files are attached(movie is too big, only attach one frame of movie).
Now zstack_fish1.nii(1024x1024x101) to template.nii(1024x1024x101) registration run successfully. But for movie_fish1.nii(1024x1024x924) to zstack_fish1.nii registration, i have tried following and get bad results:

1. rigid registration directly, result is a whole black file(1024x1024x101)
/usr/lib/cmtk/bin/registration --echo --initxlate --auto-multi-levels 5 -v --dofs 6 --dofs 9 -o affine1.xform zstack_fish1.nii movie_fish1.nii
WARNING: dimension 4 is greater than 3 in file movie_fish1.nii
Entering resolution level 1 out of 6...
Entering resolution level 1 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 6 out of 6...
Entering resolution level 6 out of 6...
Resulting transformation parameters:
#0d: 0.000000
#1d: 3.148835
#2d: 148.409010
#3d: 0.000000
#4d: -0.067115
#5d: -0.122770
#6d: 1.000000
#7d: 1.000049
#8d: 1.000000
#9d: 0.000000
#10d: 0.000000
#11d: 0.000000
#12d: 169.539899
#13d: 169.539899
#14d: 0.000000

/usr/lib/cmtk/bin/reformatx --echo --sinc-cosine -o result1.nii --floating movie_fish1.nii zstack_fish1.nii affine1.xform
WARNING: dimension 4 is greater than 3 in file movie_fish1.nii

result1.nii is a whole black file(1024x1024x101)

2.pick one frame of movie(f1_trace_100.nii, generated by figi, 1024x1024) to register, result is still whole black as result1.nii
/usr/lib/cmtk/bin/registration --echo --initxlate --auto-multi-levels 5 -v --dofs 6 --dofs 9 -o affine2.xform zstack_fish1.nii f1_trace_100.nii
Entering resolution level 1 out of 6...
Entering resolution level 1 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 6 out of 6...
Entering resolution level 6 out of 6...
Resulting transformation parameters:
#0d: 0.000000
#1d: 3.148835
#2d: 148.541592
#3d: 0.012584
#4d: 0.033557
#5d: 0.114850
#6d: 1.000000
#7d: 1.000000
#8d: 1.000000
#9d: 0.000000
#10d: 0.000000
#11d: 0.000000
#12d: 169.539899
#13d: 169.539899
#14d: 0.000000

/usr/lib/cmtk/bin/reformatx --echo --sinc-cosine -o result2.nii --floating f1_trace_100.nii zstack_fish1.nii affine2.xform

the result file is the same as result1.nii, whole black 1024x1024x101

3. pick one frame of movie, and register to one plane of zstack(40/101), generate a single black plane
After this, i saw forum and noticed Prof. Jefferis mentioned CMTK only deal with 3d volume, so i will not put details here.

I hope after 3 steps, my final results could be registered 1024x1024x924 file, still one plane and 924 timepoints, or 1024x1024x101x924 file, contain all zstacks(only warped recording plane have signal, other are blank planes) and 924 timepoints, I would like to know whether it could be implemented in cmtk or cmtk gui.

I would really appreciate it if you could help with it! Thanks a lot!

Best,
Yuxin
Jan 21, 2021  12:01 PM | Yuxin Tong - HKUST
RE: Failed to register one plane's calcium imaging trace onto template
Files is failed to upload, i saved the screenshot.
Originally posted by Yuxin Tong:
Hello everyone,

I am currently trying to register our lab's 2 photon imaging data of zebrafish larve onto a template.
My template is iteratively averaged by 10 z brain stacks on cmtk.
The objective is to register our experiment's calcium imaging activity time series(should be 1-6 planes) onto the template, so my current pipeline consists 3 steps: 
1. register calcium imaging activity experiment recording(1-6 planes, now i only tried 1 plane) onto same fish's z stack.(z stack is acquired right after the experiment recording)
2. register this fish's z stack onto template
3. apply two transformations file on experiment recording and get registered recording

Now the 2nd step I got good result but 1st and 3rd step failed.

Take one registration as example to elaborate, my z stack(zstack_fish1.nii) and template(template.nii) file size are both 1024x1024x101, there are 101 z planes from top to bottom of fish. My experiment recording file(movie_fish1.nii, format converted by figi) size is 1024x1024x924, 924 means it have 924 timepoints. It is a recording of one z plane roughly located between 39th-41th z plane of zstack_fish1.nii file. These files are attached(movie is too big, only attach one frame of movie).
Now zstack_fish1.nii(1024x1024x101) to template.nii(1024x1024x101) registration run successfully. But for movie_fish1.nii(1024x1024x924) to zstack_fish1.nii registration, i have tried following and get bad results:

1. rigid registration directly, result is a whole black file(1024x1024x101)
/usr/lib/cmtk/bin/registration --echo --initxlate --auto-multi-levels 5 -v --dofs 6 --dofs 9 -o affine1.xform zstack_fish1.nii movie_fish1.nii
WARNING: dimension 4 is greater than 3 in file movie_fish1.nii
Entering resolution level 1 out of 6...
Entering resolution level 1 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 6 out of 6...
Entering resolution level 6 out of 6...
Resulting transformation parameters:
#0d: 0.000000
#1d: 3.148835
#2d: 148.409010
#3d: 0.000000
#4d: -0.067115
#5d: -0.122770
#6d: 1.000000
#7d: 1.000049
#8d: 1.000000
#9d: 0.000000
#10d: 0.000000
#11d: 0.000000
#12d: 169.539899
#13d: 169.539899
#14d: 0.000000

/usr/lib/cmtk/bin/reformatx --echo --sinc-cosine -o result1.nii --floating movie_fish1.nii zstack_fish1.nii affine1.xform
WARNING: dimension 4 is greater than 3 in file movie_fish1.nii

result1.nii is a whole black file(1024x1024x101)

2.pick one frame of movie(f1_trace_100.nii, generated by figi, 1024x1024) to register, result is still whole black as result1.nii
/usr/lib/cmtk/bin/registration --echo --initxlate --auto-multi-levels 5 -v --dofs 6 --dofs 9 -o affine2.xform zstack_fish1.nii f1_trace_100.nii
Entering resolution level 1 out of 6...
Entering resolution level 1 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 2 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 3 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 4 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 5 out of 6...
Entering resolution level 6 out of 6...
Entering resolution level 6 out of 6...
Resulting transformation parameters:
#0d: 0.000000
#1d: 3.148835
#2d: 148.541592
#3d: 0.012584
#4d: 0.033557
#5d: 0.114850
#6d: 1.000000
#7d: 1.000000
#8d: 1.000000
#9d: 0.000000
#10d: 0.000000
#11d: 0.000000
#12d: 169.539899
#13d: 169.539899
#14d: 0.000000

/usr/lib/cmtk/bin/reformatx --echo --sinc-cosine -o result2.nii --floating f1_trace_100.nii zstack_fish1.nii affine2.xform

the result file is the same as result1.nii, whole black 1024x1024x101

3. pick one frame of movie, and register to one plane of zstack(40/101), generate a single black plane
After this, i saw forum and noticed Prof. Jefferis mentioned CMTK only deal with 3d volume, so i will not put details here.

I hope after 3 steps, my final results could be registered 1024x1024x924 file, still one plane and 924 timepoints, or 1024x1024x101x924 file, contain all zstacks(only warped recording plane have signal, other are blank planes) and 924 timepoints, I would like to know whether it could be implemented in cmtk or cmtk gui.

I would really appreciate it if you could help with it! Thanks a lot!

Best,
Yuxin
Jan 21, 2021  10:01 PM | Greg Jefferis
RE: Failed to register one plane's calcium imaging trace onto template
I can only give you some rough guidance, but I would do as follows

1. average each time series calcium recording over time reducing 4D->3D stack
2. register the 3D average stack to that fish's anatomical stack
3. register fish's anatomical stack to the template

now you have two 3D -> 3D registrations that link the 3D space of your time series data to your template. You now have two options

1. transform your time series data to the template
2. transform the template to your time series data

2 is actually much easier if your goal is to see e.g. how calcium activity lines up with 3D anatomical regions.
I only know how to do 1 by splitting up the time points and writing separate files for each (script in imageJ?)

To apply this the command line would look something like:

1. reformat --floating calcium-timepoint.nii template.nii reg1 reg2
2. reformat --floating template.nii calcium-avg.nii -- --inverse reg2 --inverse reg1
[or compute the registrations in the opposite direction]

There are fancier variations to deal with movement in the initial time series if this is an issue. I would be very happy to hear advice from anyone else who has processed functional image data.

Best, Greg.
Jan 22, 2021  01:01 AM | Kevin Mann
RE: Failed to register one plane's calcium imaging trace onto template
Hey there Yuxin, 

I agree with Greg's overall approach (reducing 4d to 3d for registration) but I do have a few other thoughts to add for doing this with functional data. 

First I would recommend using an average of a smallish (up to you but i usually use something like 100 frames) number of frames for the 4d-3d average. This might not matter depending on your setup but if there is motion in your imaging setup averaging over many frames can blur the final image. I would also use that same average to do motion correction (gonna make a plug here, but we describe doing this exact procedure with a fly brain back in 2017 in this paper). I recommend using ANTs now for motion correction currently but I've had good results from AFNI's 3dvolreg (it's faster but doesn't do deformations). 

As for the application of the registrations I go by the best practices that human neuroscientists have shared with me. That is that it's best to do as little warping to your functional data as possible. Therefore I always warp the template to the functional data rather than the other way around (This is also what Greg suggested you do as well). Somebody with more technical skills might say it doesn't matter, I honestly don't know. 

Hope that helps. Let me know if you (or Greg) have any other questions. 

-KM
Jan 23, 2021  11:01 PM | Greg Jefferis
RE: Failed to register one plane's calcium imaging trace onto template
Thanks, Kevin for the additional information. Kevin's paper is here https://www.sciencedirect.com/science/article/pii/S0960982217308138

Dealing with motion artefacts in the functional data is another class of sometimes complex registration problem. I have sometimes done a stack reg on the the functional data for motion correction and then used an average image of that to bridge to anatomical data. I'd be happy to see some more details of using AFNI's 3dvolreg that you mention.

Besides the points already mentioned mapping a mask in template space on your functional data has the advantage of reformatting much less image data. Your functional data will be very oversampled if you transform it from 6 to 101 slices.