# How to import DSI Studio trk.gz files

**URL:** <https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052>\
**Category:** SlicerDMRI\
**Created:** [December 14, 2021, 12:53pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052 "2021-12-14T12:53:19Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![William\_McCuddy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_mccuddy/32/13501_2.png) [@William\_McCuddy](https://discourse.slicer.org/u/William_McCuddy)\
**Post date:** [December 14, 2021, 12:53pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/1 "2021-12-14T12:53:20Z")

</div>

Hello,

Just checking in to see if anyone is working on a way to import tracts generated in DSI studio (.trk.gz) into 3d Slicer. I’ve tried converting to vtk via TrackVis, but the orientation was off and I could not figure out how to fix it. If there is not a way to get .trk files into slicer, does anyone have a straight forward way to make this conversion that allow for adjusting the orientation?

Thanks in advance for your help.

Will

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 14, 2021, 2:12pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/2 "2021-12-14T14:12:39Z")

</div>

> [@William\_McCuddy](#):
>
> I’ve tried converting to vtk via TrackVis, but the orientation was off and I could not figure out how to fix it.

Usually when meshes appear with unexpected orientation it is due to difference in coordinate system (LPS/RAS). If you are loading a mesh file (.vtk, .ply, .stl, … file ) and the coordinate system is not specified in the file header then Slicer assumes DICOM convention (LPS), but you can choose RAS after you select the file (in “Add data” window click on “Show options” in the top-right corner).

These topics may also help:

> [@Load DSI Studio (\*.trk.gz) or TrackVis (\*.trk) tracks in Slicer](https://discourse.slicer.org/t/load-dsi-studio-trk-gz-or-trackvis-trk-tracks-in-slicer/1356):
>
> Does anyone have experience converting and then loading fibertrack generated by these software into 3D Slicer ? Is there any recommended pathway to export tracts and import them into Slicer ? We are thinking of these approaches: improve export to vtk (fiberbundle) in software like DSI Studio. add IO support for .trk.gz, .trk … Thanks for your input References: format .trk.gz: [http://dsi-studio.labsolver.org/](http://dsi-studio.labsolver.org/) / [Subpages - DSI Studio—A Tractography Software Tool](http://dsi-studio.labsolver.org/system/app/pages/subPages?path=/Manual) format .trk: [http://www…](http://www.trackvis.org/)

> [@Diffusion module in 4.13 version cannot complete the reconstruction of fiber bundle](https://discourse.slicer.org/t/diffusion-module-in-4-13-version-cannot-complete-the-reconstruction-of-fiber-bundle/19896):
>
> Win10 64 I don’t know if this is a mistake My friend and I have tried multiple versions of 4.13 Slicer But in the last step, when setting the seed to display the fiber bundle, it can’t be displayed. The same data, the same steps, the fiber bundle can be displayed normally in version 4.11. Can the developer test whether the fiber bundle can be rebuilt in the latest 4.13 version？ This is the same mrb file in 4.11 Version[捕获]

Let us know how it works.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 14, 2021, 6:19pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/3 "2021-12-14T18:19:23Z")

</div>

> [@William\_McCuddy](#):
>
> I’ve tried converting to vtk via TrackVis, but the orientation was off and I could not figure out how to fix it.

Be sure to install SlicerDMRI and open your vtk files as FiberBundles nodes. VTK files do not declare their space, so Slicer reads them in LPS, FiberBundles are always RAS (since they may contain tensors-per-vertex that are in RAS we didn’t change the convention when Slicer changed to LPS).

---

<div class="post-metadata">

**Author:** ![William\_McCuddy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_mccuddy/32/13501_2.png) [@William\_McCuddy](https://discourse.slicer.org/u/William_McCuddy)\
**Post date:** [December 15, 2021, 12:21am UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/4 "2021-12-15T00:21:30Z")

</div>

Thank you all for your response. Unfortunately, still no luck.

I have the DMRI module installed and tried opening as a model (RAS and LPS) and fiber bundle (which defaults to LPS).

I think I have figured out a few things though. It doesn’t look like an orientation problem but a spacing problem. In the attached picture you can see the same track in 3 different locations. All tracts came from dsi studio then were converted to .vtk in TrackVis. The green tract on the left is LPC and the yellow on the right is RAS. For both the yellow tracts I added a FLAIR series to dsi studio and exported tracts “in slice (FLAIR) space”. Of note the FLAIR and DTI were acquired in the same session (so implicitly co-regesistered). Although that clearly didn’t help.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/c/3c661aa3b7cb92948172843a371e6aec49de77c0.jpeg)

I have reviewed all the dsi studio threads and the closest thing I have have been able to find is some code from the guys at nibable [https://nipy.org/nibabel/devel/biaps/biap\_0005.html](https://nipy.org/nibabel/devel/biaps/biap_0005.html)

However, my coding skills are modest at best and I can’t figure out how to implement what they’re proposing.

Here is the same tract (created in dsi studio) being displayed in TrackVis:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/d/ad99f7835f544ddaa9ae5f4b09ff0d29ecf04001.jpeg)

So, it seems there is a problem with saving as vtk file. Perhaps, as was mentioned, the lack of header information in vtk files is the problem. I’m just not sure what to do about it.

Any additional thoughts are greatly appreciated. I really want to get the tracts into 3dslicer because, for all other image modalities, I really appreciate the flexibility and rendering options. The ability to integrate tracts from dsi studio is last piece of the “puzzle” I’ve been working on 🙂

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 16, 2021, 3:57pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/5 "2021-12-16T15:57:09Z")

</div>

It’s a good question and one we would like to see solved. Like most groups the SlicerDMRI effort has focused mostly on making sure we save/reload our own data correctly and I think the vtk format and our coordinate systems are pretty well documented. Perhaps you can get similar documentation about what DSI Studio assumptions are then the link would be clear.

Alternatively there are very good tractography solutions in SlicerDMRI (e.g. UKF Tractography) and if you have the seeds you could try that. Is there something special about the DSI Studio tracts that SlicerDMRI doesn’t support?

---

<div class="post-metadata">

**Author:** ![William\_McCuddy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_mccuddy/32/13501_2.png) [@William\_McCuddy](https://discourse.slicer.org/u/William_McCuddy)\
**Post date:** [December 16, 2021, 6:39pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/6 "2021-12-16T18:39:51Z")

</div>

Thanks for your response. Here is what DSI studio says about saving tracts:  
“DSI Studio saves tracks in the native diffusion voxel space rotated to “LPS”. The coordinates are voxel coordinates started from (0,0,0) at the most left/anterior/bottom point of the image volume. The orientation is (+right,+posterior, +top). For example, (1,2,3) = [the left most 1st voxel, the most anterior second voxel, the bottom 3rd voxel].” [http://dsi-studio.labsolver.org/Manual/Fiber-Tracking](http://dsi-studio.labsolver.org/Manual/Fiber-Tracking)

However this is all saved a trk file. Specifics regarding trk file are spelled out here: [http://www.trackvis.org/docs/?subsect=fileformat](http://www.trackvis.org/docs/?subsect=fileformat) . Maybe TrackVis is doing something weird to the data when it converts from trk to vtk.

I guess it would be nice if 3dslicer could import trk files. Are there any plans for this in the future?

After some more digging I found this tutorial ([https://dipy.org/documentation/1.4.1./examples\_built/streamline\_formats/#example-streamline-formats](https://dipy.org/documentation/1.4.1./examples_built/streamline_formats/#example-streamline-formats)) on Nipy, which may be helpful for others with similar issue. It looks like they might have some code to transform vtk to trk in whatever anatomical scan space you add. I haven’t had time yet to test but will report back if it works.

I like DSI studio because of the option for generalized Q sampling reconstruction, which seems to produce good results even with noisy clinical data and seems to track pretty well through edematous tissue, built in features for eddy distortion correction, template-based seeding approach (that warps the template to patients native space so all tracking occurs in native space), and ability to export trk file. Also, it has pretty good documentation and discussion board. I’m also just more familiar with it than other software. However, maybe I will give the tracking analysis in slicer a try.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 16, 2021, 7:18pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/7 "2021-12-16T19:18:03Z")

</div>

> [@William\_McCuddy](#):
>
> I guess it would be nice if 3dslicer could import trk files. Are there any plans for this in the future?

It’s probably not in our critical path, so no. There have been some [discussions recently](https://github.com/nipy/nibabel/issues/942) among various groups about a new standard for tractography and if that takes off I could imaging that would be a good target for integration.

---

<div class="post-metadata">

**Author:** ![jhlegarreta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jhlegarreta/32/66542_2.png) [@jhlegarreta](https://discourse.slicer.org/u/jhlegarreta)\
**Post date:** [July 12, 2023, 6:52pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/8 "2023-07-12T18:52:24Z")

</div>

Sorry to chime in here. I would be interested in Slicer being able to read TRK, and potentially TCK, files. I may be willing to invest some time into this if maintainers could provide some initial pointers and thoughts, and maybe an estimate of how hard they consider this would be, to start having a look at how this could be made available. Thanks.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 12, 2023, 9:14pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/9 "2023-07-12T21:14:47Z")

</div>

If there are packages that can read these files it should be feasible to follow the same approach used in this code:

> <https://github.com/pieper/SlicerDMRI/tree/trakoio/Modules/Scripted/TRAKOFile>
>
> //github.com/pieper/SlicerDMRI/tree/trakoio/Modules/Scripted/TRAKOFile

---

<div class="post-metadata">

**Author:** ![jhlegarreta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jhlegarreta/32/66542_2.png) [@jhlegarreta](https://discourse.slicer.org/u/jhlegarreta)\
**Post date:** [July 13, 2023, 12:32pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/10 "2023-07-13T12:32:43Z")

</div>

> [@pieper](#):
>
> If there are packages that can read these files

For sure there are, easiest would be DIPY for me.

> [@pieper](#):
>
> it should be feasible to follow the same approach used in this code:

Thanks Steve. Will have a look as time permits. As far as I understand we can do an `import dipy` in Slicer without issues.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 13, 2023, 12:47pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/11 "2023-07-13T12:47:34Z")

</div>

> [@jhlegarreta](#):
>
> As far as I understand we can do an `import dipy` in Slicer without issues.

I haven’t tried recently, but I think so, yes, unless there are some dependency conflicts. There is great potential synergy so it’s good that you are investigating this.

---

<div class="post-metadata">

**Author:** ![William\_McCuddy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_mccuddy/32/13501_2.png) [@William\_McCuddy](https://discourse.slicer.org/u/William_McCuddy)\
**Post date:** [January 31, 2024, 12:44am UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/12 "2024-01-31T00:44:26Z")

</div>

Glad to see I wasn’t the only one who thought this might be useful 🙂

jhlegarreta, any luck getting trk files into 3Dslicer easily?

---

<div class="post-metadata">

**Author:** ![jhlegarreta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jhlegarreta/32/66542_2.png) [@jhlegarreta](https://discourse.slicer.org/u/jhlegarreta)\
**Post date:** [February 3, 2024, 10:17pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/13 "2024-02-03T22:17:57Z")

</div>

> jhlegarreta, any luck getting trk files into 3Dslicer easily?

Although I do believe that supporting `.trk` and `.tck` files is a much needed feature, I have not been able to have a look at how this could be supported seamlessly. I am really sorry.

---

<div class="post-metadata">

**Author:** ![egemen4552](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/egemen4552/32/77360_2.png) [@egemen4552](https://discourse.slicer.org/u/egemen4552)\
**Post date:** [July 18, 2024, 8:41pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/14 "2024-07-18T20:41:17Z")

</div>

I have to visualize my tracts in Slicer,

Is there anything about it? Can I import .tck files or .trk files?

---

<div class="post-metadata">

**Author:** ![ljod](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ljod/32/652_2.png) [@ljod](https://discourse.slicer.org/u/ljod)\
**Post date:** [October 19, 2024, 6:42pm UTC](https://discourse.slicer.org/t/how-to-import-dsi-studio-trk-gz-files/21052/15 "2024-10-19T18:42:14Z")

</div>

I’ve asked my postdoc who knows how to do this to respond.
