• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vtk.vtkImageThreshold函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vtk.vtkImageThreshold函数的典型用法代码示例。如果您正苦于以下问题:Python vtkImageThreshold函数的具体用法?Python vtkImageThreshold怎么用?Python vtkImageThreshold使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了vtkImageThreshold函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getImageMask

def getImageMask(inputVtkImageData):
    """
    @type  inputVtkImageData: C{vtkImageData}
    @param inputVtkImageData: Image data to be normalized
    
    @rtype: C{vtkImageData}
    @return: Normalized (0-1) image data
    """
    t = vtk.vtkImageThreshold()
    #t.ThresholdBetween(1,255)
    t.ThresholdByUpper(114)
    t.ReplaceInOn()
    t.SetReplaceIn(0)
    t.ReplaceOutOn()
    t.SetReplaceOut(255)
    t.SetInput(inputVtkImageData)
        
    norm = vtk.vtkImageNormalize()
    norm.SetInput(t.GetOutput())
    #norm.SetInput(inputVtkImageData)
    norm.Update()

    d = vtk.vtkImageDilateErode3D()
    d.SetKernelSize(4,4,4)
    d.SetDilateValue(1)
    d.SetErodeValue(0)
    d.SetInput(norm.GetOutput())
    return d.GetOutput()
开发者ID:pmajka,项目名称:3dbar-extensions,代码行数:28,代码来源:volume_merger.py


示例2: splitPerStructureVolumes

  def splitPerStructureVolumes(masterNode, mergeNode):
    """Make a separate label map node for each non-empty label value in the
    merged label map"""

    colorNode = mergeNode.GetDisplayNode().GetColorNode()

    accum = vtk.vtkImageAccumulate()
    accum.SetInputConnection(mergeNode.GetImageDataConnection())
    accum.Update()
    lo = int(accum.GetMin()[0])
    hi = int(accum.GetMax()[0])

    thresholder = vtk.vtkImageThreshold()
    for index in xrange(lo,hi+1):
      logging.info( "Splitting label %d..."%index )
      thresholder.SetInputConnection( mergeNode.GetImageDataConnection() )
      thresholder.SetInValue( index )
      thresholder.SetOutValue( 0 )
      thresholder.ReplaceInOn()
      thresholder.ReplaceOutOn()
      thresholder.ThresholdBetween( index, index )
      thresholder.SetOutputScalarType( mergeNode.GetImageData().GetScalarType() )
      thresholder.Update()
      if thresholder.GetOutput().GetScalarRange() != (0.0, 0.0):
        structureName = colorNode.GetColorName(index)
        logging.info( "Creating structure volume %s..."%structureName )
        structureVolume = EditUtil.structureVolume( masterNode, structureName )
        if not structureVolume:
          EditUtil.addStructure( masterNode, mergeNode, index )
        structureVolume = EditUtil.structureVolume( masterNode, structureName )
        structureVolume.GetImageData().DeepCopy( thresholder.GetOutput() )
        EditUtil.markVolumeNodeAsModified(structureVolume)
开发者ID:gregsharp,项目名称:Slicer,代码行数:32,代码来源:EditUtil.py


示例3: onApply

  def onApply(self):

    import vtkSegmentationCorePython as vtkSegmentationCore

    # Get modifier labelmap and parameters

    operation = self.scriptedEffect.parameter("Operation")

    if operation in self.operationsRequireModifierSegment:

      # Get modifier segment
      segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
      segmentation = segmentationNode.GetSegmentation()
      modifierSegmentID = self.modifierSegmentID()
      if not modifierSegmentID:
        logging.error("Operation {0} requires a selected modifier segment".format(operation))
        return
      modifierSegment = segmentation.GetSegment(modifierSegmentID)
      modifierSegmentLabelmap = modifierSegment.GetRepresentation(vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName())

      if operation == LOGICAL_COPY:
        self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierSegmentLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet)
      elif operation == LOGICAL_UNION:
        self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierSegmentLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeAdd)
      elif operation == LOGICAL_SUBTRACT:
        self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierSegmentLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeRemove)
      elif operation == LOGICAL_INTERSECT:
        selectedSegmentLabelmap = self.scriptedEffect.selectedSegmentLabelmap()
        intersectionLabelmap = vtkSegmentationCore.vtkOrientedImageData()
        vtkSegmentationCore.vtkOrientedImageDataResample.MergeImage(selectedSegmentLabelmap, modifierSegmentLabelmap, intersectionLabelmap, vtkSegmentationCore.vtkOrientedImageDataResample.OPERATION_MINIMUM, selectedSegmentLabelmap.GetExtent())
        selectedSegmentLabelmapExtent = selectedSegmentLabelmap.GetExtent()
        modifierSegmentLabelmapExtent = modifierSegmentLabelmap.GetExtent()
        commonExtent = [max(selectedSegmentLabelmapExtent[0], modifierSegmentLabelmapExtent[0]),
          min(selectedSegmentLabelmapExtent[1], modifierSegmentLabelmapExtent[1]),
          max(selectedSegmentLabelmapExtent[2], modifierSegmentLabelmapExtent[2]),
          min(selectedSegmentLabelmapExtent[3], modifierSegmentLabelmapExtent[3]),
          max(selectedSegmentLabelmapExtent[4], modifierSegmentLabelmapExtent[4]),
          min(selectedSegmentLabelmapExtent[5], modifierSegmentLabelmapExtent[5])]
        self.scriptedEffect.modifySelectedSegmentByLabelmap(intersectionLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet, commonExtent)

    elif operation == LOGICAL_INVERT:
      selectedSegmentLabelmap = self.scriptedEffect.selectedSegmentLabelmap()
      inverter = vtk.vtkImageThreshold()
      inverter.SetInputData(selectedSegmentLabelmap)
      inverter.SetInValue(1)
      inverter.SetOutValue(0)
      inverter.ReplaceInOn()
      inverter.ThresholdByLower(0)
      inverter.SetOutputScalarType(vtk.VTK_UNSIGNED_CHAR)
      inverter.Update()
      selectedSegmentLabelmap.DeepCopy(inverter.GetOutput())
      self.scriptedEffect.modifySelectedSegmentByLabelmap(selectedSegmentLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet)

    elif operation == LOGICAL_CLEAR or operation == LOGICAL_FILL:
      selectedSegmentLabelmap = self.scriptedEffect.selectedSegmentLabelmap()
      vtkSegmentationCore.vtkOrientedImageDataResample.FillImage(selectedSegmentLabelmap, 1 if operation == LOGICAL_FILL else 0, selectedSegmentLabelmap.GetExtent())
      self.scriptedEffect.modifySelectedSegmentByLabelmap(selectedSegmentLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet)

    else:
      logging.error("Uknown operation: {0}".format(operation))
开发者ID:ZeneticX,项目名称:Slicer,代码行数:60,代码来源:SegmentEditorLogicalEffect.py


示例4: onApply

  def onApply(self):
    try:
      # Get master volume image data
      import vtkSegmentationCorePython as vtkSegmentationCore
      masterImageData = self.scriptedEffect.masterVolumeImageData()
      # Get modifier labelmap
      modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
      originalImageToWorldMatrix = vtk.vtkMatrix4x4()
      modifierLabelmap.GetImageToWorldMatrix(originalImageToWorldMatrix)
      # Get parameters
      min = self.scriptedEffect.doubleParameter("MinimumThreshold")
      max = self.scriptedEffect.doubleParameter("MaximumThreshold")

      self.scriptedEffect.saveStateForUndo()

      # Perform thresholding
      thresh = vtk.vtkImageThreshold()
      thresh.SetInputData(masterImageData)
      thresh.ThresholdBetween(min, max)
      thresh.SetInValue(1)
      thresh.SetOutValue(0)
      thresh.SetOutputScalarType(modifierLabelmap.GetScalarType())
      thresh.Update()
      modifierLabelmap.DeepCopy(thresh.GetOutput())
    except IndexError:
      logging.error('apply: Failed to threshold master volume!')
      pass

    # Apply changes
    self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet)

    # De-select effect
    self.scriptedEffect.selectEffect("")
开发者ID:BRAINSia,项目名称:Slicer,代码行数:33,代码来源:SegmentEditorThresholdEffect.py


示例5: __init__

  def __init__(self):
    self.lookupTable = vtk.vtkLookupTable()
    self.lookupTable.SetRampToLinear()
    self.lookupTable.SetNumberOfTableValues(2)
    self.lookupTable.SetTableRange(0, 1)
    self.lookupTable.SetTableValue(0,  0, 0, 0,  0)
    self.colorMapper = vtk.vtkImageMapToRGBA()
    self.colorMapper.SetOutputFormatToRGBA()
    self.colorMapper.SetLookupTable(self.lookupTable)
    self.thresholdFilter = vtk.vtkImageThreshold()
    self.thresholdFilter.SetInValue(1)
    self.thresholdFilter.SetOutValue(0)
    self.thresholdFilter.SetOutputScalarTypeToUnsignedChar()

    # Feedback actor
    self.mapper = vtk.vtkImageMapper()
    self.dummyImage = vtk.vtkImageData()
    self.dummyImage.AllocateScalars(vtk.VTK_UNSIGNED_INT, 1)
    self.mapper.SetInputData(self.dummyImage)
    self.actor = vtk.vtkActor2D()
    self.actor.VisibilityOff()
    self.actor.SetMapper(self.mapper)
    self.mapper.SetColorWindow(255)
    self.mapper.SetColorLevel(128)

    # Setup pipeline
    self.colorMapper.SetInputConnection(self.thresholdFilter.GetOutputPort())
    self.mapper.SetInputConnection(self.colorMapper.GetOutputPort())
开发者ID:BRAINSia,项目名称:Slicer,代码行数:28,代码来源:SegmentEditorThresholdEffect.py


示例6: ROIfromImages

  def ROIfromImages(self,inputImage,ROIImage,radius,iterations,connectivity,newROI):
    #TODO: sistemare valori
    #col=self.ROI.GetDisplayNode().GetColorNode()
    bg=0
    fg=1

    if newROI:
      #slicer.util.delayDisplay('thresholding...')
      thresh = vtk.vtkImageThreshold()
      thresh.SetInputData(inputImage)

      lo, hi = inputImage.GetScalarRange()
      min=lo + 0.25 * (hi-lo)
      max=hi

      thresh.ThresholdBetween(min, max)
      thresh.SetInValue(fg)
      thresh.SetOutValue(bg)
      thresh.SetOutputScalarType(ROIImage.GetScalarType())
      thresh.Modified()
      thresh.Update()

      ROIImage.DeepCopy(thresh.GetOutput())

      try:
        self.markVolumeNodeAsModified(self.ROI)
      except:
        pass

    if radius>0:
      ImageBuffer = vtk.vtkImageData()
      ImageBuffer.DeepCopy(ROIImage)

      eroder = slicer.vtkImageErodeExt()
      eroder.SetInputData(ROIImage)
      eroder.SetOutput(ImageBuffer)
      
      #slicer.util.delayDisplay('create kernel')
      #eroder.SetForeground(fg)
      eroder.SetbutForeground(True)
      eroder.SetBackground(bg)
      eroder.setRadius(radius,radius,1)
      if connectivity==0:
        eroder.SetNeighborTo8()
      elif connectivity==1:
        eroder.SetNeighborTo4()
      else:
        eroder.setConnectivity2D()
        
      for f in range(1,int(ROIImage.GetScalarRange()[1]+1)):
        eroder.SetForeground(f)

        #slicer.util.delayDisplay('eroding label = ' + str(f))

        for n in range(iterations):
          ImageBuffer.DeepCopy(ROIImage)
          eroder.Update()
          ROIImage.DeepCopy(ImageBuffer)
          
      eroder.SetOutput(None)
开发者ID:gina-belmonte,项目名称:SlicerExtension-QASuite,代码行数:60,代码来源:ErodeImage.py


示例7: __init__

 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkImageThreshold(), 'Processing.',
         ('vtkImageData',), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkImageThreshold.py


示例8: onApply

  def onApply(self):
    try:
      # Get master volume image data
      import vtkSegmentationCore
      masterImageData = vtkSegmentationCore.vtkOrientedImageData()
      self.scriptedEffect.masterVolumeImageData(masterImageData)
      # Get edited labelmap
      editedLabelmap = self.scriptedEffect.parameterSetNode().GetEditedLabelmap()
      # Get parameters
      min = self.scriptedEffect.doubleParameter("MinimumThreshold")
      max = self.scriptedEffect.doubleParameter("MaximumThreshold")

      # Save state for undo
      #TODO:
      #self.undoRedo.saveState()

      # Perform thresholding
      thresh = vtk.vtkImageThreshold()
      thresh.SetInputData(masterImageData)
      thresh.ThresholdBetween(min, max)
      thresh.SetInValue(1)
      thresh.SetOutValue(0)
      thresh.SetOutputScalarType(editedLabelmap.GetScalarType())
      thresh.Update()
      editedLabelmap.DeepCopy(thresh.GetOutput())
    except IndexError:
      logging.error('apply: Failed to threshold master volume!')
      pass

    # Notify editor about changes.
    # This needs to be called so that the changes are written back to the edited segment
    self.scriptedEffect.apply()
    
    # De-select effect
    self.scriptedEffect.selectEffect("")
开发者ID:ming-hai,项目名称:SlicerRT,代码行数:35,代码来源:SegmentEditorThresholdEffect.py


示例9: computeStatistics

  def computeStatistics(self, segmentID):
    import vtkSegmentationCorePython as vtkSegmentationCore
    requestedKeys = self.getRequestedKeys()

    segmentationNode = slicer.mrmlScene.GetNodeByID(self.getParameterNode().GetParameter("Segmentation"))

    if len(requestedKeys)==0:
      return {}

    containsLabelmapRepresentation = segmentationNode.GetSegmentation().ContainsRepresentation(
      vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName())
    if not containsLabelmapRepresentation:
      return {}

    segment = segmentationNode.GetSegmentation().GetSegment(segmentID)
    segBinaryLabelName = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName()
    segmentLabelmap = segment.GetRepresentation(segBinaryLabelName)

    if (not segmentLabelmap
      or not segmentLabelmap.GetPointData()
      or not segmentLabelmap.GetPointData().GetScalars()):
      # No input label data
      return {}

    # We need to know exactly the value of the segment voxels, apply threshold to make force the selected label value
    labelValue = 1
    backgroundValue = 0
    thresh = vtk.vtkImageThreshold()
    thresh.SetInputData(segmentLabelmap)
    thresh.ThresholdByLower(0)
    thresh.SetInValue(backgroundValue)
    thresh.SetOutValue(labelValue)
    thresh.SetOutputScalarType(vtk.VTK_UNSIGNED_CHAR)
    thresh.Update()

    #  Use binary labelmap as a stencil
    stencil = vtk.vtkImageToImageStencil()
    stencil.SetInputData(thresh.GetOutput())
    stencil.ThresholdByUpper(labelValue)
    stencil.Update()

    stat = vtk.vtkImageAccumulate()
    stat.SetInputData(thresh.GetOutput())
    stat.SetStencilData(stencil.GetOutput())
    stat.Update()

    # Add data to statistics list
    cubicMMPerVoxel = reduce(lambda x,y: x*y, segmentLabelmap.GetSpacing())
    ccPerCubicMM = 0.001
    stats = {}
    if "voxel_count" in requestedKeys:
      stats["voxel_count"] = stat.GetVoxelCount()
    if "volume_mm3" in requestedKeys:
      stats["volume_mm3"] = stat.GetVoxelCount() * cubicMMPerVoxel
    if "volume_cm3" in requestedKeys:
      stats["volume_cm3"] = stat.GetVoxelCount() * cubicMMPerVoxel * ccPerCubicMM
    return stats
开发者ID:Slicer,项目名称:Slicer,代码行数:57,代码来源:LabelmapSegmentStatisticsPlugin.py


示例10: growCut

  def growCut(self):
    growCutFilter = vtkITK.vtkITKGrowCutSegmentationImageFilter()
    background = self.getScopedBackground()
    gestureInput = self.getScopedLabelInput()
    growCutOutput = self.getScopedLabelOutput()

    if not self.areInputsValid():
      logging.warning(self.getInvalidInputsMessage())

    # set the make a zero-valued volume for the output
    # TODO: maybe this should be done in numpy as a one-liner
    thresh = vtk.vtkImageThreshold()
    thresh.ReplaceInOn()
    thresh.ReplaceOutOn()
    thresh.SetInValue(0)
    thresh.SetOutValue(0)
    thresh.SetOutputScalarType( vtk.VTK_SHORT )
    if vtk.VTK_MAJOR_VERSION <= 5:
      thresh.SetInput( gestureInput )
    else:
      thresh.SetInputData( gestureInput )
    thresh.SetOutput( growCutOutput )
    thresh.Update()
    growCutOutput.DeepCopy( gestureInput )

    if vtk.VTK_MAJOR_VERSION <= 5:
      growCutFilter.SetInput( 0, background )
      growCutFilter.SetInput( 1, gestureInput )
      growCutFilter.SetInput( 2, growCutOutput )
    else:
      growCutFilter.SetInputData( 0, background )
      growCutFilter.SetInputData( 1, gestureInput )
      growCutFilter.SetInputConnection( 2, thresh.GetOutputPort() )

    objectSize = 5. # TODO: this is a magic number
    contrastNoiseRatio = 0.8 # TODO: this is a magic number
    priorStrength = 0.003 # TODO: this is a magic number
    segmented = 2 # TODO: this is a magic number
    conversion = 1000 # TODO: this is a magic number

    spacing = gestureInput.GetSpacing()
    voxelVolume = reduce(lambda x,y: x*y, spacing)
    voxelAmount = objectSize / voxelVolume
    voxelNumber = round(voxelAmount) * conversion

    cubeRoot = 1./3.
    oSize = int(round(pow(voxelNumber,cubeRoot)))

    growCutFilter.SetObjectSize( oSize )
    growCutFilter.SetContrastNoiseRatio( contrastNoiseRatio )
    growCutFilter.SetPriorSegmentConfidence( priorStrength )
    growCutFilter.Update()

    growCutOutput.DeepCopy( growCutFilter.GetOutput() )

    self.applyScopedLabel()
开发者ID:kingofpanda,项目名称:Slicer,代码行数:56,代码来源:GrowCutEffect.py


示例11: applyThreshold

 def applyThreshold(labelNode, outValue):
   imageData = labelNode.GetImageData()
   backgroundValue = 0
   thresh = vtk.vtkImageThreshold()
   thresh.SetInputData(imageData)
   thresh.ThresholdByLower(0)
   thresh.SetInValue(backgroundValue)
   thresh.SetOutValue(outValue)
   thresh.SetOutputScalarType(vtk.VTK_UNSIGNED_CHAR)
   thresh.Update()
   labelNode.SetAndObserveImageData(thresh.GetOutput())
开发者ID:QIICR,项目名称:Reporting,代码行数:11,代码来源:CustomSegmentEditor.py


示例12: preview

  def preview(self,color=None):

    if not self.editUtil.getBackgroundImage() or not self.editUtil.getLabelImage():
      return

    #
    # make a lookup table where inside the threshold is opaque and colored
    # by the label color, while the background is transparent (black)
    # - apply the threshold operation to the currently visible background
    #   (output of the layer logic's vtkImageReslice instance)
    #

    if not color:
      color = self.getPaintColor

    if not self.lut:
      self.lut = vtk.vtkLookupTable()

    self.lut.SetRampToLinear()
    self.lut.SetNumberOfTableValues( 2 )
    self.lut.SetTableRange( 0, 1 )
    self.lut.SetTableValue( 0,  0, 0, 0,  0 )
    r,g,b,a = color
    self.lut.SetTableValue( 1,  r, g, b,  a )

    if not self.map:
      self.map = vtk.vtkImageMapToRGBA()
    self.map.SetOutputFormatToRGBA()
    self.map.SetLookupTable( self.lut )

    if not self.thresh:
      self.thresh = vtk.vtkImageThreshold()
    sliceLogic = self.sliceWidget.sliceLogic()
    backgroundLogic = sliceLogic.GetBackgroundLayer()
    if vtk.VTK_MAJOR_VERSION <= 5:
      self.thresh.SetInput( backgroundLogic.GetReslice().GetOutput() )
    else:
      self.thresh.SetInputConnection( backgroundLogic.GetReslice().GetOutputPort() )
    self.thresh.ThresholdBetween( self.min, self.max )
    self.thresh.SetInValue( 1 )
    self.thresh.SetOutValue( 0 )
    self.thresh.SetOutputScalarTypeToUnsignedChar()
    if vtk.VTK_MAJOR_VERSION <= 5:
      self.map.SetInput( self.thresh.GetOutput() )
      self.map.Update()
      self.cursorMapper.SetInput( self.map.GetOutput() )
    else:
      self.map.SetInputConnection( self.thresh.GetOutputPort() )
      self.cursorMapper.SetInputConnection( self.map.GetOutputPort() )

    self.cursorActor.VisibilityOn()

    self.sliceView.scheduleRender()
开发者ID:kingofpanda,项目名称:Slicer,代码行数:53,代码来源:ThresholdEffect.py


示例13: __init__

 def __init__(self, img, threshold, xysmoothing, zsmoothing, color, alpha):
     dataImporter = vtk.vtkImageImport()
     simg = np.ascontiguousarray(img, np.uint8)
     dataImporter.CopyImportVoidPointer(simg.data, len(simg.data))
     dataImporter.SetDataScalarTypeToUnsignedChar()
     dataImporter.SetNumberOfScalarComponents(1)
     dataImporter.SetDataExtent(0, simg.shape[2]-1, 0, simg.shape[1]-1, 0, simg.shape[0]-1)
     dataImporter.SetWholeExtent(0, simg.shape[2]-1, 0, simg.shape[1]-1, 0, simg.shape[0]-1)
     self.__smoother = vtk.vtkImageGaussianSmooth()
     self.__smoother.SetStandardDeviation(xysmoothing, xysmoothing, zsmoothing)
     self.__smoother.SetInputConnection(dataImporter.GetOutputPort())
     self.__threshold = vtk.vtkImageThreshold()
     self.__threshold.SetInputConnection(self.__smoother.GetOutputPort())
     self.__threshold.ThresholdByUpper(threshold)
     self.__threshold.ReplaceInOn()
     self.__threshold.SetInValue(1)
     self.__threshold.ReplaceOutOn()
     self.__threshold.SetOutValue(0)
     self.__threshold.Update()
     contour = vtk.vtkDiscreteMarchingCubes()
     contour.SetInputConnection(self.__threshold.GetOutputPort())
     contour.ComputeNormalsOn()
     contour.SetValue(0, 1)
     contour.Update()
     smoother = vtk.vtkWindowedSincPolyDataFilter()
     smoother.SetInputConnection(contour.GetOutputPort())
     smoother.NonManifoldSmoothingOn()
     smoother.NormalizeCoordinatesOn()
     smoother.Update()
     triangleCellNormals=vtk.vtkPolyDataNormals()
     triangleCellNormals.SetInputConnection(smoother.GetOutputPort())
     triangleCellNormals.ComputeCellNormalsOn()
     triangleCellNormals.ComputePointNormalsOff()
     triangleCellNormals.ConsistencyOn()
     triangleCellNormals.AutoOrientNormalsOn()
     triangleCellNormals.Update()
     triangleCellAn = vtk.vtkMeshQuality()
     triangleCellAn.SetInputConnection(triangleCellNormals.GetOutputPort())
     triangleCellAn.SetTriangleQualityMeasureToArea()
     triangleCellAn.SaveCellQualityOn()
     triangleCellAn.Update()
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(triangleCellAn.GetOutputPort())
     mapper.ScalarVisibilityOn()
     mapper.SetScalarRange(.3, 1)
     mapper.SetScalarModeToUsePointData()
     colorLookupTable = vtk.vtkLookupTable()
     colorLookupTable.SetHueRange(.6, 1)
     colorLookupTable.Build()
     mapper.SetLookupTable(colorLookupTable)
     self.SetMapper(mapper)
     self.GetProperty().SetColor(*color)
     self.GetProperty().SetOpacity(alpha)
开发者ID:LeeKamentsky,项目名称:q3dstack,代码行数:53,代码来源:q3dstack.py


示例14: __init__

    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)
        NoConfigModuleMixin.__init__(self)

        # these will be our markers
        self._inputPoints = None

        # we can't connect the image input directly to the masksource,
        # so we have to keep track of it separately.
        self._inputImage = None
        self._inputImageObserverID = None

        # we need to modify the mask (I) as well.  The problem with a
        # ProgrammableFilter is that you can't request GetOutput() before
        # the input has been set... 
        self._maskSource = vtk.vtkProgrammableSource()
        self._maskSource.SetExecuteMethod(self._maskSourceExecute)
        
        # we'll use this to synthesise a volume according to the seed points
        self._markerSource = vtk.vtkProgrammableSource()
        self._markerSource.SetExecuteMethod(self._markerSourceExecute)
        # second input is J (the marker)

        # we'll use this to change the markerImage into something we can use
        self._imageThreshold = vtk.vtkImageThreshold()
        # everything equal to or above 1.0 will be "on"
        self._imageThreshold.ThresholdByUpper(1.0)
        self._imageThresholdObserverID = self._imageThreshold.AddObserver(
            'EndEvent', self._observerImageThreshold)
        
        self._viewFrame = self._createViewFrame(
            {'Module (self)' : self})

        # we're not going to give imageErode any input... that's going to
        # to happen manually in the execute_module function :)
        self._imageErode = vtk.vtkImageContinuousErode3D()
        self._imageErode.SetKernelSize(3,3,3)

        module_utils.setup_vtk_object_progress(self, self._imageErode,
                                           'Performing greyscale 3D erosion')
        

        self._sup = vtk.vtkImageMathematics()
        self._sup.SetOperationToMax()
        self._sup.SetInput1(self._imageErode.GetOutput())
        self._sup.SetInput2(self._maskSource.GetStructuredPointsOutput())

        # pass the data down to the underlying logic
        self.config_to_logic()
        # and all the way up from logic -> config -> view to make sure
        self.syncViewWithLogic()
开发者ID:fvpolpeta,项目名称:devide,代码行数:52,代码来源:modifyHomotopySlow.py


示例15: create_overlay

    def create_overlay(self, emphysemavalue, severeemphysemavalue):
        """Creates an overlay for the slice-based volume view
           0: no emphysema
           1: moderate emphysema
           2: severe emphysema
        """
        
    	self._view_frame.SetStatusText("Creating Overlay...")
    	mask = vtk.vtkImageMask()
    	mask2 = vtk.vtkImageMask()
    	threshold = vtk.vtkImageThreshold()
    	threshold2 = vtk.vtkImageThreshold()
    	math=vtk.vtkImageMathematics()
    
    	mask.SetInput(self.image_data)
    	mask.SetMaskInput(self.mask_data)
    
    	threshold.SetInput(mask.GetOutput())
    	threshold.ThresholdByLower(emphysemavalue)
    	threshold.SetOutValue(0)
    	threshold.SetInValue(1)

    	threshold2.SetInput(mask.GetOutput())
    	threshold2.ThresholdByLower(severeemphysemavalue)
    	threshold2.SetOutValue(1)
    	threshold2.SetInValue(2)

    	math.SetOperationToMultiply()
    	math.SetInput1(threshold.GetOutput())
    	math.SetInput2(threshold2.GetOutput())

    	math.Update()

    	overlay = math.GetOutput()
    	self.slice_viewer1.set_overlay_input(None)
    	self.slice_viewer1.set_overlay_input(overlay)
    	self.render()
    	self._view_frame.SetStatusText("Created Overlay")
开发者ID:fvpolpeta,项目名称:devide,代码行数:38,代码来源:EmphysemaViewer.py


示例16: onGradientInNewVolBtnClicked

    def onGradientInNewVolBtnClicked(self):
        # Result is not right!
        volumeNode = slicer.util.getNode("MRHead")
        ijkToRas = vtk.vtkMatrix4x4()
        volumeNode.GetIJKToRASMatrix(ijkToRas)
        imageData = volumeNode.GetImageData()
        extent = imageData.GetExtent()

        imageSize = imageData.GetDimensions()
        imageSpacing = imageData.GetSpacing()
        voxelType = vtk.VTK_FLOAT

        # Create empty image volume
        imageData_2 = vtk.vtkImageData()
        imageData_2.SetDimensions(imageSize[0] / 2, imageSize[1] / 2, imageSize[2] / 2)
        imageData_2.SetSpacing(imageSpacing)
        imageData_2.AllocateScalars(voxelType, 0)

        thresholder = vtk.vtkImageThreshold()
        thresholder.SetInputData(imageData_2)
        thresholder.SetInValue(0)
        thresholder.SetOutValue(0)

        volumeNode_2 = slicer.vtkMRMLScalarVolumeNode()
        volumeNode_2.SetSpacing(imageSpacing)
        volumeNode_2.SetImageDataConnection(thresholder.GetOutputPort())

        # Add volume to scene
        scene = slicer.mrmlScene
        scene.AddNode(volumeNode_2)
        displayNode = slicer.vtkMRMLScalarVolumeDisplayNode()
        scene.AddNode(displayNode)
        colorNode = slicer.util.getNode("Grey")
        displayNode.SetAndObserveColorNodeID(colorNode.GetID())
        volumeNode_2.SetAndObserveDisplayNodeID(displayNode.GetID())
        volumeNode_2.CreateDefaultStorageNode()

        # npData = slicer.util.array('MRHead')
        impVol = vtk.vtkImplicitVolume()
        impVol.SetVolume(imageData)

        for k in xrange(extent[4], extent[5] / 2 + 1):
            for j in xrange(extent[2], extent[3] / 2 + 1):
                for i in xrange(extent[0], extent[1] / 2 + 1):
                    g = impVol.FunctionGradient(i, j, k)
                    gradient = math.sqrt(g[0] ** 2 + g[1] ** 2 + g[2] ** 2)
                    imageData_2.SetScalarComponentFromFloat(i, j, k, 0, gradient)

        imageData_2.Modified()
开发者ID:quentan,项目名称:SlicerScript,代码行数:49,代码来源:ModifyVolume.py


示例17: buildSimpleLabelMap

    def buildSimpleLabelMap(self, image, inValue, outValue):

        threshold = vtk.vtkImageThreshold()
        threshold.SetInputData(image)
        threshold.ThresholdByLower(0)
        threshold.ReplaceInOn()
        threshold.ReplaceOutOn()
        threshold.SetOutValue(outValue)
        threshold.SetInValue(inValue)
        threshold.Update()

        outVolumeData = vtk.vtkImageData()
        outVolumeData.DeepCopy(threshold.GetOutput())

        return outVolumeData
开发者ID:vmtk,项目名称:SlicerExtension-VMTK,代码行数:15,代码来源:LevelSetSegmentation.py


示例18: Execute

    def Execute(self):

        if self.Image == None:
            self.PrintError('Error: No input image.')

        thresholdFilter = vtk.vtkImageThreshold()
        thresholdFilter.SetInputData(self.Image)
        thresholdFilter.ThresholdByUpper(self.Threshold)
        thresholdFilter.ReplaceInOn()
        thresholdFilter.ReplaceOutOn()
        thresholdFilter.SetInValue(self.UpperLabel)
        thresholdFilter.SetOutValue(self.LowerLabel)
        thresholdFilter.SetOutputScalarTypeToShort()
        thresholdFilter.Update()

        self.Image = thresholdFilter.GetOutput()
开发者ID:samsmu,项目名称:vmtk,代码行数:16,代码来源:vmtkimagebinarize.py


示例19: ImageThreshold

    def ImageThreshold(self, image, threshold_value):
        """Threshold an image"""

        image.SetReleaseDataFlag(1)
        _filter = vtk.vtkImageThreshold()
        _filter.ReplaceInOn()
        _filter.ReplaceOutOn()
        _filter.SetInValue(1)
        _filter.SetOutValue(0)
        _filter.SetOutputScalarType(3)
        _filter.SetInput(image.GetRealImage())
        _filter.ThresholdByUpper(threshold_value)
        _filter.AddObserver('ProgressEvent', self.HandleVTKProgressEvent)
        _filter.SetProgressText("Thresholding...")
        logging.info("Image thresholded")
        return MVImage.MVImage(_filter.GetOutputPort(), input=image)
开发者ID:andyTsing,项目名称:MicroView,代码行数:16,代码来源:MicroViewImageProcessor.py


示例20: calculateFrontAndRear

	def calculateFrontAndRear(self, reader, maxPush, minPush):
		"""
		Method to calculate front and rear of objects in the track
		Image parameter must be vtkImageData
		"""
		spacing = []
		for i in range(len(self.voxelSize)):
			spacing.append(self.voxelSize[i] / self.voxelSize[0])
		
		for tp in range(self.mintp, self.maxtp + 1):
			label = self.values[tp]
			com1 = self.points[tp]

			if tp == self.maxtp: # Use latest direction
				for i in range(len(direction)):
					direction[i] *= -1.0
			else:
				com2 = self.points[tp+1]
				direction = []
				for i in range(len(com1)):
					direction.append(com2[i] - com1[i])

			# Polygon data
			image = reader.getDataSet(tp)
			objThreshold = vtk.vtkImageThreshold()
			objThreshold.SetInput(image)
			objThreshold.SetOutputScalarTypeToUnsignedChar()
			objThreshold.SetInValue(255)
			objThreshold.SetOutValue(0)
			objThreshold.ThresholdBetween(label,label)
			marchingCubes = vtk.vtkMarchingCubes()
			marchingCubes.SetInput(objThreshold.GetOutput())
			marchingCubes.SetValue(0, 255)
			marchingCubes.Update()
			polydata = marchingCubes.GetOutput()
			polydata.Update()

			front = self.locateOutmostPoint(polydata, com1, direction, maxPush, minPush)
			for i in range(len(direction)):
				direction[i] *= -1.0
			rear = self.locateOutmostPoint(polydata, com1, direction, maxPush, minPush)
			for i in range(len(front)):
				front[i] /= spacing[i]
				rear[i] /= spacing[i]
			
			self.fronts[tp] = tuple(front)
			self.rears[tp] = tuple(rear)
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:47,代码来源:Track.py



注:本文中的vtk.vtkImageThreshold函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vtk.vtkImageViewer函数代码示例发布时间:2022-05-26
下一篇:
Python vtk.vtkImageShiftScale函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap