def createModel(self,labelVolume):
   """
   Create the 3D model from the airway label
   """
   modelHierarchyCollection = slicer.mrmlScene.GetNodesByName('AirwayModelHierarchy')
   if( modelHierarchyCollection.GetNumberOfItems() >= 1 ):
     modelHierarchy = modelHierarchyCollection.GetItemAsObject(0)
   else:
     nodeType = 'vtkMRMLModelHierarchyNode'
     modelHierarchy = slicer.mrmlScene.CreateNodeByClass(nodeType)
     modelHierarchy.SetScene(slicer.mrmlScene)
     modelHierarchy.SetName(slicer.mrmlScene.GetUniqueNameByString('AirwayModelHierarchy'))
     slicer.mrmlScene.AddNode(modelHierarchy)
   
   parameters = {}
   parameters["InputVolume"] = labelVolume.GetID()
   parameters["ModelSceneFile"] = modelHierarchy.GetID()
   parameters["Name"] = 'AirwayModel'
   #parameters["FilterType"] = 'Laplacian'
   parameters["Smooth"] = 20
   parameters["Decimate"] = 0.10
   
   modelMaker = slicer.modules.modelmaker
   slicer.cli.run(modelMaker, None, parameters,True)
 
   lm = slicer.app.layoutManager()
   threeDView = lm.threeDWidget( 0 ).threeDView()
   threeDView.resetFocalPoint()
   threeDView.lookFromViewAxis(ctk.ctkAxesWidget().Anterior)
   
   return True
Пример #2
0
 def createModel(self,labelVolume):
   """
   Create the 3D model from the airway label
   """
   modelHierarchyCollection = slicer.mrmlScene.GetNodesByName('AirwayModelHierarchy')
   if( modelHierarchyCollection.GetNumberOfItems() >= 1 ):
     modelHierarchy = modelHierarchyCollection.GetItemAsObject(0)
   else:
     nodeType = 'vtkMRMLModelHierarchyNode'
     modelHierarchy = slicer.mrmlScene.CreateNodeByClass(nodeType)
     modelHierarchy.SetScene(slicer.mrmlScene)
     modelHierarchy.SetName(slicer.mrmlScene.GetUniqueNameByString('AirwayModelHierarchy'))
     slicer.mrmlScene.AddNode(modelHierarchy)
   
   parameters = {}
   parameters["InputVolume"] = labelVolume.GetID()
   parameters["ModelSceneFile"] = modelHierarchy.GetID()
   parameters["Name"] = 'AirwayModel'
   #parameters["FilterType"] = 'Laplacian'
   parameters["Smooth"] = 20
   parameters["Decimate"] = 0.10
   
   modelMaker = slicer.modules.modelmaker
   slicer.cli.run(modelMaker, None, parameters,True)
 
   lm = slicer.app.layoutManager()
   threeDView = lm.threeDWidget( 0 ).threeDView()
   threeDView.resetFocalPoint()
   threeDView.lookFromViewAxis(ctk.ctkAxesWidget().Anterior)
   
   return True
  def onStartSegmentationButton(self):
    inputVolume = self.inputSelector.currentNode()
    inputName = inputVolume.GetName()
    
    inputNode = slicer.util.getNode(inputName)
    instUIDs = inputNode.GetAttribute('DICOM.instanceUIDs').split()
    fileName = slicer.dicomDatabase.fileForInstance(instUIDs[0])
    patientAge = slicer.dicomDatabase.fileValue(fileName,'0010,1010')
    patientAge=patientAge[1:3]
    age_str = str(patientAge)
    self.age.setText(age_str)
    
    # Analyze histogram of the image to work out the second peak intensity value
    start = timeit.default_timer()

    self.LungNoduleSegmentationButton.enabled = False   
    seedPoint = self.fiducialListSelector.currentNode()
    
    inputNodeArray = slicer.util.array(inputVolume.GetID())
    maskedImage = inputNodeArray[inputNodeArray >= -1024]

    edges=[] 
    I_max = maskedImage.max()
    I_min = maskedImage.min()

    for val in range(I_min,I_max+2): 
      edges.append(val)

    I_max =float(I_max)
    I_min =float(I_min)

    maskedImage = maskedImage.astype(float)
   
    histogram,bins = numpy.histogram(maskedImage,bins=edges)

    mx, mn = self.peakdetect(histogram)

    threshold = (-1024+bins[mx[0][0]]) / 2
    if threshold < -800:
      maskedImage = inputNodeArray[inputNodeArray >= -1000]

      edges=[] 
      I_max = maskedImage.max()
      I_min = maskedImage.min()

      for val in range(I_min,I_max+2): 
        edges.append(val)

      I_max =float(I_max)
      I_min =float(I_min)

      maskedImage = maskedImage.astype(float)
   
      histogram,bins = numpy.histogram(maskedImage,bins=edges)

      mx, mn = self.peakdetect(histogram)

      threshold = (-1024+bins[mx[0][0]]) / 2
 
    print threshold
    
    stop = timeit.default_timer()
    print "Histogram anaylis: ", stop - start, "sec" 

    # Segment the lung surface

    start = timeit.default_timer()

    nodeType = 'vtkMRMLScalarVolumeNode'
    self.lungLabelNode = slicer.mrmlScene.CreateNodeByClass(nodeType)
    self.lungLabelNode.SetLabelMap(1)
    self.lungLabelNode.SetScene(slicer.mrmlScene)
    self.lungLabelNode.SetName(slicer.mrmlScene.GetUniqueNameByString('LungLabel'))
    slicer.mrmlScene.AddNode(self.lungLabelNode)

    LungSegmentationModule = slicer.modules.lungsegmentationcli
    lungLabelColor = 1

    parameters = {
       "InputVolume": inputVolume,
       "OutputVolume": self.lungLabelNode,
       "Lower": -1024,
       "Upper": threshold,
       "lungColor": lungLabelColor,
    }

    slicer.cli.run( LungSegmentationModule, None, parameters, wait_for_completion = True )

    stop = timeit.default_timer()
    print "Lung segmentation: ", stop - start, "sec" 

    # Segment the selected nodule
    start = timeit.default_timer()

    nodeType = 'vtkMRMLScalarVolumeNode'
    self.noduleLabelNode = slicer.mrmlScene.CreateNodeByClass(nodeType)
    self.noduleLabelNode.SetLabelMap(1)
    self.noduleLabelNode.SetScene(slicer.mrmlScene)
    self.noduleLabelNode.SetName(slicer.mrmlScene.GetUniqueNameByString('NoduleLabel'))
    slicer.mrmlScene.AddNode(self.noduleLabelNode)

    LungNoduleSegmentationModule = slicer.modules.lungnodulesegmentationcli
    labelColor = 6

    parameters = {
       "InputVolume": inputVolume,
       "InputLungLabel": self.lungLabelNode, 
       "OutputVolume": self.noduleLabelNode,
       "seed": seedPoint,
       "noduleColor": labelColor,
    }

    NoduleSegmentationNode = slicer.cli.run( LungNoduleSegmentationModule, None, parameters, wait_for_completion = True )

    stop = timeit.default_timer()
    print "Nodule segmentation: ", stop - start, "sec"     

    self.FissuresNode = slicer.mrmlScene.CreateNodeByClass(nodeType)
    self.FissuresNode.SetLabelMap(1)
    self.FissuresNode.SetScene(slicer.mrmlScene)
    self.FissuresNode.SetName(slicer.mrmlScene.GetUniqueNameByString('FissuresVolume'))
    slicer.mrmlScene.AddNode(self.FissuresNode)

    FissuresSegmentationModule = slicer.modules.lungfissuresegmentationcli

    params = {
       "InputVolume": inputVolume,
       "InputLungLabel": self.lungLabelNode, 
       "OutputVolume": self.FissuresNode,
    }

    slicer.cli.run( FissuresSegmentationModule, None, params, wait_for_completion = True )

    self.LobesNode = slicer.mrmlScene.CreateNodeByClass(nodeType)
    self.LobesNode.SetLabelMap(1)
    self.LobesNode.SetScene(slicer.mrmlScene)
    self.LobesNode.SetName(slicer.mrmlScene.GetUniqueNameByString('LobesVolume'))
    slicer.mrmlScene.AddNode(self.LobesNode)

    LobesSegmentationModule = slicer.modules.lunglobesegmentationcli

    params = {
       "InputVolume": inputVolume,
       "LabelMapVolume": self.lungLabelNode, 
       "FissuresVolume": self.FissuresNode,
       "OutputVolume": self.LobesNode
    }

    slicer.cli.run( LobesSegmentationModule, None, params, wait_for_completion = True )

    # Create 3D model of the segment nodule 
    start = timeit.default_timer()

    modelHierarchyCollection = slicer.mrmlScene.GetNodesByName('NoduleModelHierarchy')
    if( modelHierarchyCollection.GetNumberOfItems() >= 1 ):
      modelHierarchy = modelHierarchyCollection.GetItemAsObject(0)
    else:
      modelHierarchy = slicer.vtkMRMLModelHierarchyNode()
      modelHierarchy.SetName(slicer.mrmlScene.GetUniqueNameByString('NoduleModelHierarchy'))
      slicer.mrmlScene.AddNode(modelHierarchy)
    
    parameters = {}
    parameters["InputVolume"] = self.noduleLabelNode.GetID()
    parameters["ModelSceneFile"] = modelHierarchy.GetID()
    parameters["Name"] = 'NoduleModel'
    parameters["Smooth"] = 20
    parameters["Decimate"] = 0.10
    
    modelMaker = slicer.modules.modelmaker
    slicer.cli.run( modelMaker, None, parameters, wait_for_completion = True )
  
    lm = slicer.app.layoutManager()
    threeDView = lm.threeDWidget( 0 ).threeDView()
    threeDView.resetFocalPoint()
    threeDView.lookFromViewAxis(ctk.ctkAxesWidget().Anterior)

    stop = timeit.default_timer()
    print "Model maker: ", stop - start, "sec" 

    # Evaluate malignancy of the nodule

    nodulePosition = NoduleSegmentationNode.GetParameterDefault(2,0)
    noduleSize = NoduleSegmentationNode.GetParameterDefault(2,1)
    noduleRoundness = NoduleSegmentationNode.GetParameterDefault(2,2)
    noduleCavityWallThickness = NoduleSegmentationNode.GetParameterDefault(2,3) 
    noduleCalcificationPattern = NoduleSegmentationNode.GetParameterDefault(2,4)

    size_str = str(noduleSize) + ' mm'
    self.size.setText(size_str)

    smoothness_str = 'Smooth'
    noduleRoundness = float(noduleRoundness)
    if noduleRoundness < 0.7:
      smoothness_str = 'Spiculated'

    self.spiculation.setText(smoothness_str)

    thickness_str = 'Not Cavitated'
    noduleCavityWallThickness = float(noduleCavityWallThickness)
    if (noduleCavityWallThickness >= 0.1 and noduleCavityWallThickness < 100.0):
      print noduleCavityWallThickness
      thickness_str = str(noduleCavityWallThickness) + ' mm'
    self.thickness.setText(thickness_str)

    lobesImageData = self.LobesNode.GetImageData()

    nodulePosition = eval(nodulePosition)

    lobeValue = lobesImageData.GetScalarComponentAsDouble(int(nodulePosition[0]),int(nodulePosition[1]),int(nodulePosition[2]), 0)
    position_str = 'Right Upper Lobe'
    if lobeValue == 5:
      position_str = 'Right Middle Lobe'
    elif lobeValue == 6:
      position_str = 'Right Lower Lobe'
    elif lobeValue == 7:
      position_str = 'Left Upper Lobe'
    elif lobeValue == 8:
      position_str = 'Left Lower Lobe'

    self.location.setText(position_str)

    calc_str = 'Benign Pattern'
    if noduleCalcificationPattern == 'false':
      calc_str = 'No Calcification'

    self.calcification.setText(calc_str)
 
    self.LungNoduleSegmentationButton.enabled = True

    self.calculateProbability()
    self.RecomputeButton.enabled = True