In [1]:
import tractography_latest as tract
reload(tract)
Out[1]:
In [2]:
## Load TIFF stack (takes file path to a folder containing .tif or .tiff files)
## Note that all files should have the same name and only differ in numbering (where numbering corresponds
## to the z dimension).
test = tract.tiff_stack_to_array('/home/tractography_test/CTT/demo/data/')
In [3]:
## Generate FSL and DTK format .nii structure tensors.
## These can be used for visualizing the tracts. Note that parameters used here were outlined in the
## original MATLAB documentation.
fsl, dtk = tract.generate_FSL_and_DTK_structure_tensor(test, 'test_data', dogsigmaArr=[1], gausigmaArr=[0.5]);
In [4]:
## Optional: Generate a .nii.gz brain mask from TIF/TIFF stacks by saving a TIFF stack of a mask as a .nii.gz
mask = tract.tiff_stack_to_nii('/home/tractography_test/CTT/demo/mask-brain/', 'brainmask')
In [5]:
## Validation: compare results of Python outputs wiht MATLAB demo outputs from:
## https://github.com/mcnablab/CTT/tree/master/demo
import nibabel as nib
MATLAB_output = nib.load("/home/tractography_test/CTT/demo/result/dog1gau0.5/dtk_tensor.nii.gz")
In [6]:
MATLAB_np_array = MATLAB_output.get_data()
In [7]:
## Validate that dimensions of MATLAB/Python are the same:
print dtk.shape
print MATLAB_np_array.shape
In [8]:
## Elementwise, compare values of dtk (Python output) and MATLAB_np_array at 1e-4 tolerance levels.
import numpy as np
truth_boolean = np.isclose(dtk, MATLAB_np_array, rtol = 1e-4)
In [9]:
## Calculate the number of correct inputs
correct_number = np.sum(truth_boolean == True); # Total possible = 4,374,000
print correct_number
In [10]:
## Percentage correct (at the 1e-4 value)
print correct_number / (4374000.0)
In [ ]: