Child pages
  • Brain Stem from BRAINSABC
Skip to end of metadata
Go to start of metadata

 

 

This page illustrates a pseudo code creating brain stem mask from BAW.

Requirements:

  • Inputs:
    • Landmarks from BRAINSConstellationDetector
    • White matter mask from BRAINSABC or other sources
  • Tools:
    • The pseudo code is tested with SimpleITK

Landmark used

Crop the white matter mask based on landmark detected: (See Selecting fiducial points for Landmarks for details)

  • lat_right
  • lat_left
  • mid_lat
  • mid_prim_sup
  • PC

Result

2D View (Click to navigate)3D View (Click to rotate)

Code

import SimpleITK as sitk


def brainStem(project, site, session):
    ## read in fcsv file
    import csv
    import os
    #project='KIDSHD'
    #site='115'
    #session='60080110'
    bawDir='/Shared/johnsonhj/HDNI/20140703_Peg_6yrFemaleTrial/20140703_PegKIDS_Baseline_Results'
    fcsvFilename=os.path.join(bawDir,project,site,session,'ACPCAlign/BCD_ACPC_Landmarks.fcsv')
    myLandmark=dict()
    with open(fcsvFilename, 'r') as myLandmarkFile:
        landmark = myLandmarkFile.readlines()[8:]
        for row in landmark:
            lmk = row.split(',')
            lmkID = lmk[0]
            lmkX = float(lmk[1])
            lmkY = float(lmk[2])
            lmkZ = float(lmk[3])
            #print (lmkID, lmkX, lmkY, lmkZ)
            #RAS to LPS 
            myLandmark[lmkID] = (-lmkX,-lmkY,lmkZ)

    ## read a label file
    brainLblFilename=os.path.join(bawDir,project,site,session,'TissueClassify/fixed_brainlabels_seg.nii.gz')
    brainLbl = sitk.ReadImage(brainLblFilename)

    ## get index locations
    myLmkIndex = dict()
    for lmk in myLandmark.keys():
        myLmkIndex[ lmk ] = brainLbl.TransformPhysicalPointToIndex( myLandmark[lmk] )

    imageSize=brainLbl.GetSize()
    print( imageSize)

    #print ("imageSize : "+str(imageSize))
    cropLower = (myLmkIndex['lat_right'][0],myLmkIndex['mid_lat'][1],0)
	#using "dens-axis" for the inferior cutting point:::
    cropLower = (myLmkIndex['lat_right'][0],
                 myLmkIndex['mid_lat'][1],
                 myLmkIndex['dens_axis'][2])
    cropUpper   = (myLmkIndex['lat_left'][0],myLmkIndex['mid_prim_sup'][1],myLmkIndex['PC'][2])
    cropUpper   = (imageSize[0]-myLmkIndex['lat_left'][0],
                   imageSize[1]-myLmkIndex['mid_prim_sup'][1],
                   imageSize[2]-myLmkIndex['PC'][2])


    print ("cropLower : "+str(cropLower))
    print ("cropUpper : "+str(cropUpper))
    brainStem_area = sitk.Crop(brainLbl, cropLower, cropUpper)
    #print brainStem_area.GetSize()

    brainStem = sitk.BinaryThreshold( brainStem_area, 1,1)
    #sitk.WriteImage(brainStem,"./brainStem.nii.gz")

    brainStem_connected=sitk.ConnectedComponent(brainStem)
    brainStem_largest_connected=sitk.BinaryThreshold(brainStem_connected,1,1)
    #sitk.WriteImage(brainStem_connected,"./brainStem_connected.nii.gz")
    outFilename=os.path.join(".",session +'_brainstem.nii.gz')
    print outFilename
    print( brainLbl.TransformPhysicalPointToIndex((0.3403646589881779, -14.789848887708027, -4.83813045025024)))
    sitk.WriteImage(brainStem_largest_connected,outFilename)

  • No labels