MIC-DKFZ / TractSeg

Automatic White Matter Bundle Segmentation
Apache License 2.0
225 stars 76 forks source link

--plot3D not a valid argument for plot_tractometry_results #118

Closed smeisler closed 4 years ago

smeisler commented 4 years ago

Hello,

When I run as instructed in the documentation, I get an error unrecognized arguments: --plot3D metric . This is especially confusing because I looked at the code for plot_tractometry_results, and I can see the code for --plot3D towards the bottom where arguments are parsed. The rest of the function (e.g. making the group comparison plots) seems to be working fine. Do you know what the problem might be? This is running on TractSeg 2.1.1, checked out earlier today.

Thanks, Steven

wasserth commented 4 years ago

Does it work if you use the master branch?

pip install --upgrade https://github.com/MIC-DKFZ/TractSeg/archive/master.zip
smeisler commented 4 years ago

Looks like that did the trick, thanks! Even though I am having some graphical rendering issues, closing the issue for now, since they are probably not tractseg related.

smeisler commented 4 years ago

Sorry to reopen so soon, but the 3d images appear to be empty (below is the left AF as an example, which I know is not empty for this particular subject) The codes does run without error though, and the 2D group comparison plots are still looking fine. image

Before running the code I make sure the brain mask is one directory above the TractSeg output folder for the plotted subject. Then, the code I used to run looks like the following (I used trk trackings): plot_tractometry_results --plot3D metric -i /PATH/TO/subjects.txt -o test.png --tracking_format trk

My output folder is called TractSeg as opposed to tractseg_output), and in these folders I have tractometry csv files for fa, md, rd, and ad. The header to my subjects txt file looks like the following: # tractometry_path=/PATH/TO/SUBJECT/FOLDERS/SUBJECT_ID/TractSeg/fa.csv # bundles=AF_left UF_left CST_left IFO_left # plot_3D=/PATH/TO/FIRST/SUBJECT/TractSeg/

Also, as a related note, I found that even the 2D plot program would crash at the very end of the program when creating the figure if I used matplotlib >= 3, maybe due to the backend choice. It only ran to completion after rolling back to matplotlib 2.

wasserth commented 4 years ago

Is your subject in MNI space? The camera of the 3D rendering is adjusted to have the right view angle for MNI space. So if your subject is not in MNI space it might face the wrong direction. For the 3D rendering it is a bit painful to get the orientation right for very format. I always work with trk_legacy. Does it work for you if you use trk_legacy? Then the format would be the issue.

smeisler commented 4 years ago

image That worked, thanks! I'll see if it works with trk_legacy while in subject space. To this end, my workflow has been: 1) Get FA_2_MNI transform matrix 2) Register all diffusion files and scalar maps to MNI (starting from raw diffusion), with appropriate bvec rotating 3) Generate CSD peaks on MNI diffusion file with MrTrix and flip them across X-axis 3) Run TractSeg (bundle, endings, TOM) on MNI 4) Register all of these outputs back to subject space, including peaks (which I do not binarize like the bundles and endings) 5) Run Tracking individually on both MNI and subject space

Before running Tracking in subject space, should I generate peaks in subject space with MrTrix or simply register them from MNI (or does it make a difference)? Alternatively, is there a way to cut out the intermediary steps and just register the .trk files themself to subject space?

Also, ignore the comment I made earlier about matplotlib; my conda environment was just disorganized beyond repair, so after a new install and very deliberate package installing, everything is working better. I do get a warning when it enters the rendering stage that may be worth addressing.

path/to/conda/environment/lib/python3.7/site-packages/setuptools/distutils_patch.py:26: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.

smeisler commented 4 years ago

I compared the Left AF picture with the Right AF picture, and it looks like that 1) the same orientation is used to render both pictures, and that 2) left and right may be switched, based on how close the right and left fibers appear when looking at the left side of the brain as in the pictures. Also, is the color bar that is included in the picture on the Tractometry wiki supposed to be generated as well?

AF Right

image

AF Left

image

wasserth commented 4 years ago

Thanks for the colorbar hint. There was a bug. If you pull the newest master the colorbar should work now.

TractSeg only works properly if your images are roughly aligned with MNI space. Using trk_legacy does not change that. After you ran all Tracking you can transform your results back to subject space if you want to. However TractSeg does not provide any commands for that. Transforming the trk files should be possible but I do not know which is the best tool to do this (flirt does not work with streamline files). plot_tractometry_results only works properly in MNI space.

AF_left and right should be fine I guess. In tractseg/libs/plot_utils.py you can uncomment line 499 then you should get an interactive 3D view where you can rotate the brain.

smeisler commented 4 years ago

Color bar does indeed work now, thanks!. However, I am still suspicious that somehow left and right are getting switched. Below are the Left CST as rendered by plot_tractometry_results (MNI) and by TrackVis (warped back to subject space), both presumably from an anterior perspective.

plot_tractometry_results

image

TrackVis

image

wasserth commented 4 years ago

I will do a more in depth investigation into the left/right issue. Might take a little while.

wasserth commented 4 years ago

I updated the code. Now the left/right issue in the 3D plot should be fixed. (When showing a bundle, the correct bundle was shown, but in 3D it was plotted flipped to the other side. Now the flipping should be correct).

smeisler commented 4 years ago

Thanks!