In [1]:
import tractography_latest as tract
reload(tract)


Out[1]:
<module 'tractography_latest' from 'tractography_latest.pyc'>

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]);


Start DoG Sigma on 1
Start Gauss Sigma with gausigma = 0.5
Generating Gaussian kernel...
Blurring gradient products...
Saving a copy for this Gaussian sigma...
4374000
4374000
Completed computing structure tensor on test_data!

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


(90, 90, 90, 6)
(90, 90, 90, 6)

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


4238655

In [10]:
## Percentage correct (at the 1e-4 value)

print correct_number / (4374000.0)


0.969056927298

In [ ]: