MIC-DKFZ / TractSeg

Automatic White Matter Bundle Segmentation
Apache License 2.0
229 stars 75 forks source link

different dimensions of FA and bundle segmentations #188

Open slusna-dominika opened 2 years ago

slusna-dominika commented 2 years ago

Hi all,

In an earlier version of TractSeg, one of the program outputs was a FA_MNI_isoxfm.nii (88 x 106 x 88, voxel size 2.04 isotropic) that matched voxel dimensions of bundle segmentations. Having downloaded the most recent version on my Mac a couple of weeks ago, I no longer get this output, but only FA.nii and FA_MNI.nii. The problem is that none of the FA maps matches in voxel dimensions the bundle segmentations. Here are the dimensions I get for FA and bundle segmentations in subject and MNI space:

Subject space: FA.nii (116 x 116 x 64, voxel size 1.98 x 1.98 x 2) vs. e.g. AF.nii.gz from bundle segmentations (116 x 116 x 64, voxel size 1.98 x 1.98 x 1.98) MNI space: FA_MNI.nii (145 x 174 x 145, voxel size 1.25 x 1.25 x 1.25) vs. e.g. AF.nii.gz from bundle segmentation_MNI (91 x 109 x 91, voxel size 1.98 x 1.98 x 1.98)

Thank you for any help, Dominika

wasserth commented 2 years ago

What command are you using to run TractSeg?

slusna-dominika commented 2 years ago

I run this sequence of steps:

echo "Step (1) Preprocessing the diffusion data: Motion and eddy current correction" eddy_correct $data_base/$subject_i/data/dwi.nii $data_base/$subject_i/data/eddy_corrected_data.nii.gz 0 cp $data_base/$subject_i/data/dwi_bvals $data_base/$subject_i/data/eddy_corrected_data.bvals cp $data_base/$subject_i/data/dwi_bvecs $data_base/$subject_i/data/eddy_corrected_data.bvecs

echo "Step (2) Creating a brain mask" bet $data_base/$subject_i/data/eddy_corrected_data $data_base/$subject_i/data/eddy_corrected_data_brain -m -R -f 0.3 cp $data_base/$subject_i/data/eddy_corrected_data_brain.nii.gz $data_base/$subject_i/data/nodif_brain_mask.nii.gz

echo "Step (3) Computing the diffusion tensor and derived metrics (i.e., FA, etc)" dtifit -k $data_base/$subject_i/data/eddy_corrected_data -o $data_base/$subject_i/data/recon -m $data_base/$subject_i/data/nodif_brain_mask -r $data_base/$subject_i/data/eddy_corrected_data.bvecs -b $data_base/$subject_i/data/eddy_corrected_data.bvals -w -V cp $data_base/$subject_i/data/recon_FA.nii.gz $data_base/$subject_i/data/FA.nii.gz cp $data_base/$subject_i/data/recon_MD.nii.gz $data_base/$subject_i/data/MD.nii.gz

echo "Step (4) Custom input and output path and preprocessing" TractSeg -i $data_base/$subject_i/dataS/eddy_corrected_data.nii.gz -o $data_base/$subject_i/tractseg_output --raw_diffusion_input --preprocess --preview --verbose --csd_type csd_msmt --brain_mask $data_base/$subject_i/data/nodif_brain_mask.nii.gz --output_type tract_segmentation --keep_intermediate_files --nr_cpus $ncpus

echo "Step (5) Create segmentation of start and end regions of bundles" TractSeg -i $data_base/$subject_i/tractseg_output/peaks.nii.gz -o $data_base/$subject_i/tractseg_output --output_type endings_segmentation --preprocess --verbose --nr_cpus $ncpus

echo "Step (6) Create Tract Orientation Maps and use them to do bundle-specific tracking" TractSeg -i $data_base/$subject_i/tractseg_output/peaks.nii.gz -o $data_base/$subject_i/tractseg_output --preprocess --output_type TOM --verbose --nr_cpus $ncpus

echo Step (7) Run fiber tracking" Tracking -i $data_base/$subject_i/tractseg_output/peaks.nii.gz -o $data_base/$subject_i/tractseg_output --tracking_dilation 1 --nr_fibers 10000 --verbose --tracking_format trk --nr_cpus $ncpus

wasserth commented 2 years ago

Unfortunately I have no idea what the problem might be. Could you share your data so I can try to reproduce the problem?

wasserth commented 2 years ago

I think I found the problem. I am working on a fix.

wasserth commented 2 years ago

I just pushed a fix to the newest master. Now it should work.

slusna-dominika commented 2 years ago

Dear Jakob,

Could it be that with the new master branch, there is a new error which results in: This issue has already appeared in https://github.com/MIC-DKFZ/TractSeg/issues/80

Step (7) Run fiber tracking 11%|██████████████████▍ | 8/72 [05:59<47:52, 44.89s/it] multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/home/dominika/miniconda3/lib/python3.9/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, *kwds)) File "/home/dominika/miniconda3/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar return list(map(args)) File "/home/dominika/miniconda3/lib/python3.9/site-packages/tractseg/libs/tractseg_prob_tracking.py", line 157, in process_seedpoint streamline_part1, length_1 = process_one_way(peaks, streamline1, max_nr_steps, step_size, probabilistic, File "/home/dominika/miniconda3/lib/python3.9/site-packages/tractseg/libs/tractseg_prob_tracking.py", line 52, in process_one_way dir_raw = get_at_idx(peaks, (last_point[0], last_point[1], last_point[2])) File "/home/dominika/miniconda3/lib/python3.9/site-packages/tractseg/libs/tractseg_prob_tracking.py", line 43, in get_at_idx return img[int(idx[0]), int(idx[1]), int(idx[2])] IndexError: index 64 is out of bounds for axis 2 with size 64 """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/dominika/miniconda3/bin/Tracking", line 168, in main() File "/home/dominika/miniconda3/bin/Tracking", line 158, in main tracking.track(bundle, input_path, Config.PREDICT_IMG_OUTPUT, File "/home/dominika/miniconda3/lib/python3.9/site-packages/tractseg/libs/tracking.py", line 220, in track streamlines = tractseg_prob_tracking.track(tom_peaks, max_nr_fibers=nr_fibers, smooth=5, File "/home/dominika/miniconda3/lib/python3.9/site-packages/tractseg/libs/tractseg_prob_tracking.py", line 263, in track streamlines_tmp = pool.map(partial(process_seedpoint, next_step_displacement_std=next_step_displacement_std, File "/home/dominika/miniconda3/lib/python3.9/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/home/dominika/miniconda3/lib/python3.9/multiprocessing/pool.py", line 771, in get raise self._value IndexError: index 64 is out of bounds for axis 2 with size 64

Thank you, Dominika!

wasserth commented 2 years ago

Interesting. You would have to send me the data again so I can try to reproduce the error.

slusna-dominika commented 2 years ago

Sure! I pushed my data to this repository and added you as a collaborator. Thank you!

wasserth commented 2 years ago

The --preprocess option does not properly work with TOMs unfortunately. Therefore I would recommend the following: Either register your images manually to MNI space and then run TractSeg on those images (without --preprocess) or just try in subject space without --preprocess and see if the results are good. If the images in subject space are relatively close to MNI space then this should also work well.

slusna-dominika commented 2 years ago

Hello Jakob,

I am sorry to open up this issue again, but regardless of the newest master, the FA_MNI.nii.gz and any other output image in MNI still do not coincide in dimensions. It is strange because I used the FA_2_MNI transformation matrix to register DWI to MNI space.

I have uploaded the TractSeg output to this repository which also contains raw dwi data that were added previously for the same participant.

I have used your DWI-to-MNI part of the preprocesssing script:

calc_FA dwi_denoise_unr_eddy_bias_brain nodif_brain_mask.nii.gz  # calc_FA is part of TractSeg
    dwi_spacing=$(get_image_spacing dwi.nii.gz)  # get_image_spacing is part of TractSeg
    atlas=$FSLDIR/data/standard/FMRIB58_FA_1mm.nii.gz

    #B0 2mm to MNI - mutualinfo working better
    flirt -ref $atlas -in FA.nii.gz \
    -out FA_MNI.nii.gz -omat FA_2_MNI.mat -dof 6 -cost mutualinfo -searchcost mutualinfo -interp spline

    #Register DWI to MNI
    flirt -ref $atlas \
    -in dwi_denoise_unr_eddy_bias_brain.nii.gz -out dwi_denoise_unr_eddy_bias_brain_MNI.nii.gz \
    -applyisoxfm "$dwi_spacing" -init FA_2_MNI.mat -dof 6 -interp spline
    cp -v dwi_denoise_unr_eddy_bias_brain.bvals dwi_denoise_unr_eddy_bias_brain_MNI.bvals
    rotate_bvecs dwi_denoise_unr_eddy_bias_brain.bvecs FA_2_MNI.mat \
    dwi_denoise_unr_eddy_bias_brain_MNI.bvecs

    #Transform brain mask to MNI with T1 2mm transform
    flirt -ref $atlas -in nodif_brain_mask.nii.gz \
    -out nodif_brain_mask_MNI.nii.gz -applyisoxfm "$dwi_spacing" -init FA_2_MNI.mat -dof 6
    fslmaths nodif_brain_mask_MNI.nii.gz -thr 0.5 -bin nodif_brain_mask_MNI.nii.gz

    #Remove negative values (introduced by spline interpolation)
    remove_negative_values dwi_denoise_unr_eddy_bias_brain_MNI.nii.gz \
    dwi_denoise_unr_eddy_bias_brain_MNI.nii.gz  # remove_negative_values is part of TractSeg

    #Get final files
    cp -v dwi_denoise_unr_eddy_bias_brain_MNI.bvals ../dwi.bvals
    cp -v dwi_denoise_unr_eddy_bias_brain_MNI.bvecs ../dwi.bvecs
    cp -v dwi_denoise_unr_eddy_bias_brain_MNI.nii.gz ../dwi.nii.gz
    cp -v nodif_brain_mask_MNI.nii.gz ../nodif_brain_mask.nii.gz

Thank you for all your help, Dominika