In [1]:
## Boiler plate code common to many notebooks. See the TestFilesCommonCode.ipynb for details
from __future__ import print_function
%run TestFilesCommonCode.ipynb
In [3]:
FA_filename='/scratch/TESTS/BS/DWIWorkflow_Nipype/6_RunOnACroppedFile/19568/Outputs/FA.nrrd'
t2_filename = '/Shared/sinapse/CACHE/20141001_PREDICTHD_long_Results/PHD_024/1155/19568/TissueClassify/t2_average_BRAINSABC.nii.gz'
labels_filename = '/Shared/sinapse/CACHE/20141001_PREDICTHD_long_Results/PHD_024/1155/19568/TissueClassify/complete_brainlabels_seg.nii.gz'
FA = sitk.ReadImage(FA_filename)
T2 = sitk.ReadImage(t2_filename)
labels = sitk.ReadImage(labels_filename)
myshow(T2)
myshow(FA)
myshow(sitk.LabelToRGB(labels))
In [6]:
size=labels.GetSize()
myshow(sitk.LabelToRGB(labels[size[0]//2,:,::-1]))
size=FA.GetSize()
myshow(sitk.Expand(FA[size[0]//2,:,:],[5,5,5]))
FA and label maps are in the same physical space, but they have different "sizes". Also, FA has some missing brain regions, e.g. it does not cover the CSF from the label map.
In [53]:
# Resample label map to FA image space
resFilt = sitk.ResampleImageFilter()
resFilt.SetReferenceImage(FA)
resFilt.SetOutputPixelType(labels.GetPixelIDValue())
resFilt.SetInterpolator(1) # Nearest neighbour interpolation
labels_res = resFilt.Execute(labels)
size=labels_res.GetSize()
myshow(sitk.Expand(sitk.LabelToRGB(labels_res[size[0]//2,:,:]),[5,5,5]))
In [110]:
labelID = 24
In [111]:
statFilter = sitk.LabelStatisticsImageFilter()
statFilter.Execute(FA, labels_res)
print('mean:',statFilter.GetMean(labelID))
print('std:',statFilter.GetSigma(labelID))
print('max:',statFilter.GetMaximum(labelID))
print('min:',statFilter.GetMinimum(labelID))
print('median:',statFilter.GetMedian(labelID))
print('Num of voxels:',statFilter.GetCount(labelID))
voxelSize=FA.GetSpacing()[0]*FA.GetSpacing()[1]*FA.GetSpacing()[2]
effective_volume=statFilter.GetCount(labelID) * voxelSize
print('effective_volume:',effective_volume)
#print(statFilter.GetNumberOfLabels())
FA spacing is 2mm, so the volume of each voxel in FA lattice is 8 mm^3
In [112]:
# Now resample FA to label map image space
resFilt = sitk.ResampleImageFilter()
resFilt.SetReferenceImage(labels)
FAres = resFilt.Execute(FA)
size=FAres.GetSize()
myshow(sitk.Expand(FAres[size[0]//2,:,::-1],[1,1,1]))
In [113]:
statFilter = sitk.LabelStatisticsImageFilter()
statFilter.Execute(FAres, labels)
print('mean:',statFilter.GetMean(labelID))
print('std:',statFilter.GetSigma(labelID))
print('Num of voxels:',statFilter.GetCount(labelID))
voxelSize=labels.GetSpacing()[0]*labels.GetSpacing()[1]*labels.GetSpacing()[2]
total_volume=statFilter.GetCount(labelID) * voxelSize
print('total_volume:',total_volume)
print('confidence_coeficient:',effective_volume/total_volume)
#print(statFilter.GetNumberOfLabels())
Label map spacing is 1mm, so the volume of each voxel in Label map lattice is 1 mm^3
For GLOBUS, THALAMUS and HIPPOCAMPUS, the confidence coeficient should be 1 because there is no missing part for these regions, and for each of the, the whole volume has contributed in computing the average FA. As expected computed confidence coeficient is close to 1 for these regions, and the mismatch has happened because of resampling error when label map is resampled to FA image space
In [ ]: