# Tractography export by color 

**URL:** https://discourse.slicer.org/t/tractography-export-by-color/3191
**Category:** Support
**Created:** [June 15, 2018, 1:33am UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191 "2018-06-15T01:33:32Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)
#### Post date: [June 15, 2018, 1:33am UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/1 "2018-06-15T01:33:32Z")

</div>

Hello,  
I’ve got a Tractography file in slicer with numerous colors. I’d like to export the curves with color or export the curves based on a color threshold. The idea with the latter is that I can export numerous files and bring them into another modeling program and assign the files to different layers based on color. Any ideas how to make this work?

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)
#### Post date: [June 15, 2018, 1:52am UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/2 "2018-06-15T01:52:21Z")

</div>

Please try the **Export tractography to PLY (mesh)** module, available in the SlicerDMRI extension in nightly builds (since early April).

Note that we use PLY specifically because it supports color.

Most software with STL import also supports PLY, but if you specifically need OBJ (supports color) or STL (no color) you can [convert in MeshLab](https://github.com/SlicerDMRI/SlicerDMRI/wiki/How-to-export-atlas-or-tractography-for-visualization-in-Blender).

---

<div class="post-metadata">

### Author: ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)
#### Post date: [June 15, 2018, 3:37pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/3 "2018-06-15T15:37:05Z")

</div>

Thank you. This is good to know but I’m need to keep these as curves and lines because we will be voxel printing. So to be more specific, is there a way to export curves and lines with color and/or segment these curves based on color?

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)
#### Post date: [June 15, 2018, 4:44pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/4 "2018-06-15T16:44:35Z")

</div>

What format are you looking for? I don’t know if STL support polylines, but at least VTK’s STL export does not seem to support that (the output is just a point cloud, I think; that’s why we apply a tube filter before export).

If you save as a PLY, then the colors will be stored per-vertex. If you save as VTK then the colors will be stored in an associated cell array.

Feel free to have a look at the code [here](https://github.com/SlicerDMRI/SlicerDMRI/blob/master/Modules/Scripted/TractographyExportPLY/TractographyExportPLY.py). It is Python so you can modify as-needed in a downloaded Slicer build without compiling yourself.

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)
#### Post date: [June 15, 2018, 4:51pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/5 "2018-06-15T16:51:45Z")

</div>

I should also mention that, as far as I understand, a number of people have used exactly this export process for 3D printing of tractography. The original export script is from @pieper, and we made it into a module recently because this request comes up several times a month.

---

<div class="post-metadata">

### Author: ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)
#### Post date: [June 15, 2018, 5:10pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/6 "2018-06-15T17:10:56Z")

</div>

And the process you mention and code is for the meshing ply?

It sounds like I might be able to export the vtk polylines and the color ply point cloud and color the lines by association.

Any format that exports with polylines in color works. We can work with a lot of different line based files. But the lines allow us to bitmap print or voxel print and keep file size low. Whereas the meshing is often way to big of a file.

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)
#### Post date: [June 15, 2018, 7:15pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/7 "2018-06-15T19:15:21Z")

</div>

The process I mentioned applies a tube filter to the streamlines, by default creating a 6-sided tube for each streamline, so memory usage goes up roughly 6x. # sides and radius are configurable. Each ring vertex is given the same color as the corresponding point had in Slicer’s viewer.

VTK does support polylines and is the most flexible option.

---

<div class="post-metadata">

### Author: ![Nicholas.jacobson](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Nicholas.jacobson](https://discourse.slicer.org/u/Nicholas.jacobson)
#### Post date: [June 15, 2018, 7:33pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/8 "2018-06-15T19:33:54Z")

</div>

Thanks I think I will export a vtk to rhino and then sort by direction. Then create seperate layers based on those directions.

---

<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: [June 15, 2018, 7:40pm UTC](https://discourse.slicer.org/t/tractography-export-by-color/3191/9 "2018-06-15T19:40:49Z")

</div>

A related option is to convert to voxels in Slicer using Tractography to Mask Image module. This upsamples along fibers to best fill in the intersected voxels, but it does not currently export colors. It could be helpful to take a look at the code.

It looks like we need to update the documentation for this module, as it seems to still be under the old name here:  
[https://www.slicer.org/wiki/Documentation/Nightly/Modules/FiberBundleToLabelMap](https://www.slicer.org/wiki/Documentation/Nightly/Modules/FiberBundleToLabelMap)
