demianw / tract_querier

Implementation of the White Matter Query Language and associated tools for dMRI white matter tract extraction and analysis
Other
26 stars 27 forks source link

Tck file format #18

Open gelazari opened 9 years ago

gelazari commented 9 years ago

As the software only supports the .vtk format, I would like to ask suggestions/proposals to incorporate the usage of .tck format as follows: For example, is it possible to modify the code so as to give as input .tck format, then .tck to be converted to .vtk format within the code and then continue with the execution as normally. I am asking this because the code is not very easily understood for a non professional coder without the proper documentation and i would really appreciate any help/hints.

Thanks in advance for your time and consideration

demianw commented 9 years ago

Hello @gelazari !

Tract_querier supports VTK as well as TRK (trackvis).

If you want to add tck format, you should add two functions similar to tract_querier.tractography.tractography_from_trackvis_file(filename) and tract_querier.tractography.tractography_to_trackvis_file(filename, tractography, affine=None, image_dimensions=None)

with in the same file as these. Then, modify the functions

tract_querier.tractography.tractography_from_file(filename) tract_querier.tractography.tractography_to_file(filename, tractography, **kwargs)

to add handling for the third data format transparently. The NIPy people have developed a MRTRix to TrackVis converter. You can probably use this as an example: http://nipy.sourceforge.net/nipype/interfaces/generated/nipype.interfaces.mrtrix.convert.html

Let me know if this is helpful! Best Demian

gelazari commented 9 years ago

All of the above operations should be done in the tractography.py file right?Also, in the WMQL documentation, only the support for VTK file format is mentioned i.e "A full-brain tractography in VTK format: It must be a vtkPolyData object where all the cells are lines". Anyhow, I'm only interested in the .tck format from Mrtrix and not the .trk (TrackVis) format unless needed. But what do you think is better? To incorporate the .tck format or to pre-convert my .tck files to .vtk or .trk (since you say it's supported by the querier) format? I don't know if i have the required programming skills to mess with your code.

gelazari commented 9 years ago

I also saw that the Nipy code is available in Github so the .tck functions needed to do the job are already implemented.

demianw commented 9 years ago

Regarding tck and trk, file formats in medical imaging are all but simple with many nuances. So I wouldn't mess with the code if that's not your priority. But, you are willing to make a contribution to a software package, I will be glad to help!

Also, I will update the documentation soon! Thanks for noticing.

On Feb 17, 2015, at 17:55, gelazari notifications@github.com wrote:

I also saw that the Nipy code is available in Github so the .tck functions needed to do the job are already implemented.

— Reply to this email directly or view it on GitHub.

gelazari commented 9 years ago

Of course I am willing to contribute as long as we can do it together so as to learn and at the same time improve the software for everyone. :)

mdesco commented 9 years ago

Guys,

If I may jump in, we've been developing a TractConverter tool that can save you a lot of time.

You can get it here: sudo pip install --upgrade https://github.com/MarcCote/tractconverter /archive/master.zip This is in the process of being ported to NiBabel. I have added in CC Marc-Alex and JC Houde.

You can convert from trk to tck to vtk to etc...

Maxime Descoteaux, PhD Professor Sherbrooke Connectivity Imaging Laboratory (SCIL) Centre de Recherche CHUS Computer Science department Sherbrooke University 2500 Boul. Université Sherbrooke, Québec J1K 2R1, Canada phone: +1 819 821-8000 x66129 fax: +1 819 821-8200 http://scil.dinf.usherbrooke.ca

Scientific director Visualization and Image Analysis Plateform (PAVI) http://pavi.dinf.usherbrooke.ca/

On Tue, Feb 17, 2015 at 12:57 PM, gelazari notifications@github.com wrote:

Of course I am willing to contribute as long as we can do it together so as to learn and at the same time improve the software for everyone. :)

— Reply to this email directly or view it on GitHub https://github.com/demianw/tract_querier/issues/18#issuecomment-74716391 .[image: Web Bug from https://github.com/notifications/beacon/ACEgB8s6AmW67nN4HEcXJTtjyz5TfJDSks5ns3h8gaJpZM4DhjT-.gif]

demianw commented 9 years ago

True @mdesco ! I forgot!

Thanks for jumping in!

Demian Wassermann, PhD demian.wassermann@inria.fr Research Scientist Athena Project Team INRIA Sophia Antipolis - Méditerranée 2004 route des lucioles - FR-06902

MarcCote commented 9 years ago

Once in NiBabel, I will be happy to provide a patch to the TractQuerier so it can read any streamlines format. You can watch PR https://github.com/nipy/nibabel/pull/243 for updates.

gelazari commented 9 years ago

So, to sum up, by using the TractConverter to do the conversion .tck->.trk would be more than enough for using the tracts in Tract_querier, right?

MarcCote commented 9 years ago

Yes. Let me know how it goes.

gelazari commented 9 years ago

Perfect. Thank you all @demianw @mdesco @MarcCote. I will let you know as soon as i can.

gelazari commented 9 years ago

Results in track conversion from Mrtrix3 format .tck to .vtk are perfect. After the conversion, I check if the output is similar with the input with: np.all([np.array_equal(trk_tracks, vtk_tracks) for trk_tracks, vtk_tracks in zip(trk_tracks, vtk_tracks])

And it's always good in my case.

demianw commented 9 years ago

OK @gelazari . So you are proposing to directly incorporate this code into tract_querier?

gelazari commented 9 years ago

i think that since code for conversion from one format to another exists, I find no reason for tract_querier not to incorporate direct Mrtrix (.tck) format reading and an option -o to specify the output the format of the output of the tracks. Of course it is not necessary but it would be nice, because all the necessary modules are up and running. What does @MarcCote think?

MarcCote commented 9 years ago

I'm not sure if I understood correctly. You want to add code for loading tck directly in tract_querier instead of using a third party library (e.g. NiBabel or TractConverter)?

Personally, I think tract_querier should continue using NiBabel to load streamlines. Once my PR (https://github.com/nipy/nibabel/pull/243) for supporting multiple streamlines file format is merged, it would be really easy to use. For example,

import nibabel as nib
fa = nib.load('fa.nii.gz')
streamlines = nib.streamlines.load('tractography.tck', ref=fa)

# Streamlines are in voxel space by default, send them to world space
streamlines = streamlines.to_world_space()
demianw commented 9 years ago

I agree with @MarcCote . The issue with incorporating working code, is that the largest cost in code is not having a working version but doing the maintenance. As there's already a compatible project in the community handling this, NiBabel, which is already used in tract_querier. I think it's better to wait for Marc's PR to be accepted. (And btw, great work on that @MarcCote !)