Skip to content

Commit

Permalink
BUG: Writing a work around for caudates in images where subjects have…
Browse files Browse the repository at this point in the history
… huge ventricles.
  • Loading branch information
hjmjohnson committed Jan 15, 2013
1 parent bfb0686 commit 3594601
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
16 changes: 14 additions & 2 deletions AutoWorkup/BRAINSCutCMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def xmlGenerator(args, roi=""):
outputStream.write(" TrainingModelFilename = \"na\"\n")
# outputStream.write( " TrainingModelFilename = \"/nfsscratch/PREDICT/TEST_BRAINSCut/20120828ANNModel_Model_RF100.txt\"\n")
outputStream.write(" TestVectorFilename = \"na\"\n")
outputStream.write(" Normalization = \"" + args.vectorNormalization + "\"\n")
if roi == "caudate":
outputStream.write(" Normalization = \"" + 'Linear' + "\"\n")
else:
outputStream.write(" Normalization = \"" + args.vectorNormalization + "\"\n")

outputStream.write(" />\n")

#
Expand Down Expand Up @@ -125,6 +129,8 @@ def xmlGenerator(args, roi=""):
if args.inputSubjectT2Filename is not None:
outputStream.write(" <Image Type=\"T2\" Filename=\"" + args.inputSubjectT2Filename + "\" />\n")
outputStream.write(" <Image Type=\"GadSG\" Filename=\"" + args.inputSubjectGadSGFilename + "\" />\n")
if roi == "caudate":
outputStream.write(" <Image Type=\"candiateRegion\" Filename=\"" + args.candidateRegion + "\" />\n")
# outputStream.write( " <Image Type=\"TotalGM\" Filename=\"{fn}\" />\n".format(fn=args.inputSubjectTotalGMFilename))
# outputStream.write( " <Mask Type=\"RegistrationROI\" Filename=\"{fn}\" />\n".format(fn=args.inputSubjectRegistrationROIFilename))

Expand Down Expand Up @@ -163,6 +169,9 @@ def xmlGenerator(args, roi=""):

brainscutParser = argparse.ArgumentParser(description='BRAINSCut command line argument parser')

# HACK: This is to allow special treatment of caudates with masking
brainscutParser.add_argument('--candidateRegion', help='Specify the valid candidate region for caudate', required=True)

#
# input arguments
#
Expand Down Expand Up @@ -232,7 +241,10 @@ def xmlGenerator(args, roi=""):

for roi in roiList:
currentXmlFilename = xmlGenerator(args, roi)
currentModelFilename = args.modelFilename[:-3] + '_' + roi + '.gz' # trainModelFile.txtD0060NT0060_accumben.gz
if roi == "caudate":
currentModelFilename = args.modelFilename[:-3] + '_' + roi + '_LinearWithMask.gz' # trainModelFile.txtD0060NT0060_caudate_LinearWithMask.gz
else:
currentModelFilename = args.modelFilename[:-3] + '_' + roi + '.gz' # trainModelFile.txtD0060NT0060_accumben.gz

BRAINSCutCommand = ["BRAINSCut" + " --applyModel " +
" --netConfiguration " + currentXmlFilename +
Expand Down
21 changes: 21 additions & 0 deletions AutoWorkup/PipeLineFunctionHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@
def convertToList(element):
return [ element ]

def MakeInclusionMaskForGMStructures( posteriorDictionary ):
import SimpleITK as sitk

AIR_FN=posteriorDictionary['AIR']
CSF_FN=posteriorDictionary['CSF']
VB_FN=posteriorDictionary['VB']
WM_FN=posteriorDictionary['WM']

AIR_PROB=sitk.ReadImage(AIR_FN)
CSF_PROB=sitk.ReadImage(CSF_FN)
VB_PROB=sitk.ReadImage(VB_FN)
WM_PROB=sitk.ReadImage(WM_FN)

AIR_Region=sitk.BinaryThreshold(AIR_PROB,0.51,1.01,1,0)
CSF_Region=sitk.BinaryThreshold(CSF_PROB,0.51,1.01,1,0)
VB_Region=sitk.BinaryThreshold(VB_PROB,0.51,1.01,1,0)
WM_Region=sitk.BinaryThreshold(WM_PROB,0.99,1.01,1,0) #NOTE: Higher tolerance for WM regions!

outputCandidateRegion=sitk.BinaryThreshold(AIR_Region+CSF_Region+VB_Region+WM_Region,1,100,0,1) #NOTE: Inversion of input/output definitions

return outputCandidateRegion

def makeListOfValidImages(imageFile):
if imageFile is None:
Expand Down
1 change: 1 addition & 0 deletions AutoWorkup/RF12BRAINSCutWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RF12BRAINSCutWrapperCLInputSpec(CommandLineInputSpec):
### subject specific
inputSubjectT1Filename = File(desc="Subject T1 Volume", exists=True, mandatory=True, argstr="--inputSubjectT1Filename %s")
inputSubjectT2Filename = File(desc="Subject T2 Volume", exists=True, mandatory=False, argstr="--inputSubjectT2Filename %s")
candidateRegion = File(desc="Valid region for finding GM structures", exists=True, mandatory=True, argstr="--candidateRegion %s")
inputSubjectGadSGFilename = File(desc="Subject SG Volume", exists=True, mandatory=False, argstr="--inputSubjectGadSGFilename %s")
vectorNormalization = traits.Enum("IQR", "Linear", "Sigmoid_Q01", "Sigmoid_Q05", "ZScore", "NONE",
desc="The type of intensity normalization to use", exists=True, mandatory=True, argstr="--vectorNormalization %s")
Expand Down
2 changes: 2 additions & 0 deletions AutoWorkup/WorkupT1T2.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ def WorkupT1T2(subjectid, mountPrefix, ExperimentBaseDirectoryCache, ExperimentB
myLocalSegWF[sessionid] = CreateBRAINSCutWorkflow(projectid, subjectid, sessionid, 'Segmentation',
CLUSTER_QUEUE, CLUSTER_QUEUE_LONG, BAtlas[subjectid], t1Only) # Note: Passing in the entire BAtlas Object here!

baw200.connect(PHASE_2_oneSubjWorkflow[sessionid], 'outputspec.posteriorImages', myLocalSegWF[sessionid],
"inputspec.posteriorDictionary")
baw200.connect(PHASE_2_oneSubjWorkflow[sessionid], 'outputspec.t1_average', myLocalSegWF[sessionid], "inputspec.T1Volume")

if (len(global_AllT2s[sessionid]) > 0):
Expand Down
12 changes: 11 additions & 1 deletion AutoWorkup/WorkupT1T2BRAINSCut.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ def CreateBRAINSCutWorkflow(projectid,
cutWF = pe.Workflow(name=GenerateWFName(projectid, subjectid, sessionid, WFName))

inputsSpec = pe.Node(interface=IdentityInterface(fields=['T1Volume', 'T2Volume',
'TotalGM', 'RegistrationROI',
'posteriorImageDictionary', 'RegistrationROI',
'atlasToSubjectTransform']), name='inputspec')


if not t1Only:
"""
Gradient Anistropic Diffusion images for BRAINSCut
Expand Down Expand Up @@ -157,6 +158,7 @@ def CreateBRAINSCutWorkflow(projectid,
cutWF.connect(GADT1, 'outputVolume', SGI, 'inputVolume1')
cutWF.connect(GADT2, 'outputVolume', SGI, 'inputVolume2')


"""
BRAINSCut
"""
Expand Down Expand Up @@ -194,6 +196,14 @@ def CreateBRAINSCutWorkflow(projectid,
RF12BC.inputs.outputBinaryRightGlobus = 'subjectANNLabel_r_globus.nii.gz'

cutWF.connect(inputsSpec, 'T1Volume', RF12BC, 'inputSubjectT1Filename')

from PipeLineFunctionHelpers import MakeInclusionMaskForGMStructures;
makeCandidateRegionNode = pe.Node(interface=Function(['posteriorDictionary'],
['outputCandidateRegion'],
function=MakeInclusionMaskForGMStructures), name="MakeCandidateRegion")
cutWF.connect(inputsSpec,'posteriorDictionary',makeCandidateRegionNode,'posteriorDictionary')
cutWF.connect(makeCandidateRegionNode,'outputCandidateRegion', RF12BC,'candidateRegion')

if not t1Only:
cutWF.connect(inputsSpec, 'T2Volume', RF12BC, 'inputSubjectT2Filename')
# cutWF.connect(inputsSpec,'TotalGM',RF12BC,'inputSubjectTotalGMFilename')
Expand Down

0 comments on commit 3594601

Please sign in to comment.