当前位置: 首页>>代码示例>>Python>>正文


Python vtk.vtkImageMathematics函数代码示例

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


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

示例1: Execute

    def Execute(self):

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

        if self.Image2 == None:
            self.PrintError('Error: No input image2.')

        if self.NegateImage2:
            negateFilter = vtk.vtkImageMathematics()
            negateFilter.SetInputData(self.Image2)
            negateFilter.SetOperationToMultiplyByK()
            negateFilter.SetConstantK(-1.0)
            negateFilter.Update()
            self.Image2 = negateFilter.GetOutput()

        composeFilter = vtk.vtkImageMathematics()
        composeFilter.SetInput1Data(self.Image)
        composeFilter.SetInput2Data(self.Image2)
        if self.Operation == 'min':
            composeFilter.SetOperationToMin()
        elif self.Operation == 'max':
            composeFilter.SetOperationToMax()
        elif self.Operation == 'multiply':
            composeFilter.SetOperationToMultiply()
        elif self.Operation == 'subtract':
            composeFilter.SetOperationToSubtract()
        else:
            self.PrintError('Error: Unsupported operation')
        composeFilter.Update()

        self.Image = composeFilter.GetOutput()
开发者ID:vmtk,项目名称:vmtk,代码行数:32,代码来源:vmtkimagecompose.py

示例2: IsosurfaceInitialize

    def IsosurfaceInitialize(self):

        self.PrintLog('Isosurface initialization.')

        if self.Interactive:
            queryString = "Please input isosurface level (\'n\' for none): "
            self.IsoSurfaceValue = self.ThresholdInput(queryString)
        
        imageMathematics = vtk.vtkImageMathematics()
        imageMathematics.SetInput(self.Image)
        imageMathematics.SetConstantK(-1.0)
        imageMathematics.SetOperationToMultiplyByK()
        imageMathematics.Update()

        subtract = vtk.vtkImageMathematics()
        subtract.SetInput(imageMathematics.GetOutput())
        subtract.SetOperationToAddConstant()
        subtract.SetConstantC(self.IsoSurfaceValue)
        subtract.Update()

        self.InitialLevelSets = vtk.vtkImageData()
        self.InitialLevelSets.DeepCopy(subtract.GetOutput())
        self.InitialLevelSets.Update()

        self.IsoSurfaceValue = 0.0
开发者ID:ChaliZhg,项目名称:vmtk,代码行数:25,代码来源:vmtkimageinitialization.py

示例3: ComputeKSpaceOperation

    def ComputeKSpaceOperation(self,kSpace):

        kSpaceMValue = vtk.vtkImageMathematics()
        kSpaceMValue.SetInput(kSpace)
        kSpaceMValue.SetOperationToMultiplyByK()
        kSpaceMValue.SetConstantK(self.MValue)
        kSpaceMValue.Update()

        kSpace = kSpaceMValue.GetOutput()

        if not self.KSpace:
            return kSpace
 
        if self.KSpaceOperation == 'none':
            return kSpace
       
        kSpaceMaths = vtk.vtkImageMathematics()
        if self.KSpaceOperation == 'add':
            kSpaceMaths.SetOperationToAdd()
        elif self.KSpaceOperation == 'subtract':
            kSpaceMaths.SetOperationToSubtract()
        else:
            self.PrintError('KSpaceOperation not supported.')
            return kSpace
            
        kSpaceMaths.SetInput1(self.KSpace)
        kSpaceMaths.SetInput2(kSpace)
        kSpaceMaths.Update()

        return kSpaceMaths.GetOutput()
开发者ID:151706061,项目名称:FEMRI,代码行数:30,代码来源:femrikspace.py

示例4: BuildVTKGradientBasedFeatureImage

    def BuildVTKGradientBasedFeatureImage(self):

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()

        gradientMagnitude = vtk.vtkImageGradientMagnitude()
        gradientMagnitude.SetInputConnection(cast.GetOutputPort())
        gradientMagnitude.SetDimensionality(self.Dimensionality)
        gradientMagnitude.Update()

        imageAdd = vtk.vtkImageMathematics()
        imageAdd.SetInputConnection(gradientMagnitude.GetOutputPort())
        imageAdd.SetOperationToAddConstant()
        imageAdd.SetConstantC(1.0)
        imageAdd.Update()

        imageInvert = vtk.vtkImageMathematics()
        imageInvert.SetInputConnection(imageAdd.GetOutputPort())
        imageInvert.SetOperationToInvert()
        imageInvert.SetConstantC(1E20)
        imageInvert.DivideByZeroToCOn()
        imageInvert.Update()

        self.FeatureImage = vtk.vtkImageData()
        self.FeatureImage.DeepCopy(imageInvert.GetOutput())
开发者ID:vmtk,项目名称:vmtk,代码行数:27,代码来源:vmtkimagefeatures.py

示例5: sumManualSegmentations

  def sumManualSegmentations(self, manualSegmentationsDirectory, mergedVolume):
    # Get the manual segmentations and create a single summed image
    import glob
    manualSegmentationFilenames = glob.glob(manualSegmentationsDirectory+"/*.mha")

    # Get the first image which each successive image will be added to
    reader = vtk.vtkMetaImageReader()
    reader.SetFileName(manualSegmentationFilenames[0])
    reader.Update()
    summedImage = vtk.vtkImageData()
    summedImage.SetExtent(reader.GetOutput().GetExtent())
    summedImage.AllocateScalars(vtk.VTK_UNSIGNED_CHAR,1)
    summedImage.ShallowCopy(reader.GetOutput())

    # Initialize filter to add images together
    mathFilter = vtk.vtkImageMathematics()

    # Iterate list and add each new image
    for currentFile in manualSegmentationFilenames[1:]:
      # Get new image
      reader.SetFileName(currentFile)
      reader.Update()

      # Add it to existing summation
      mathFilter.SetInput1Data(summedImage)
      mathFilter.SetInput2Data(reader.GetOutput())
      mathFilter.Update()

      # Get new summation
      summedImage.ShallowCopy(mathFilter.GetOutput())

    # Add summed image to slicer scene
    mergedVolume.SetRASToIJKMatrix(self.rasToIjk)
    mergedVolume.SetIJKToRASMatrix(self.ijkToRas)
    mergedVolume.SetAndObserveImageData(summedImage)
开发者ID:Mattel,项目名称:USBoneSegmentation,代码行数:35,代码来源:USGeometry.py

示例6: Execute

    def Execute(self):

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

        if self.LevelSets == None:
            self.PrintError('Error: No input level sets.')

        if self.NegateLevelSets:
            negateFilter = vtk.vtkImageMathematics()
            negateFilter.SetInputData(self.LevelSets)
            negateFilter.SetOperationToMultiplyByK()
            negateFilter.SetConstantK(-1.0)
            negateFilter.Update()
            self.LevelSets = negateFilter.GetOutput()

        sigmoid = vtkvmtk.vtkvmtkLevelSetSigmoidFilter()
        sigmoid.SetInputData(self.Image)
        sigmoid.SetLevelSetsImage(self.LevelSets)
        sigmoid.SetSigma(self.Sigma)
        sigmoid.SetScaleValue(self.ScaleValue)
        if self.ComputeScaleValueFromInput:
            sigmoid.ComputeScaleValueFromInputOn()
        else:
            sigmoid.ComputeScaleValueFromInputOff()
        sigmoid.Update()
 
        self.Image = sigmoid.GetOutput()
开发者ID:151706061,项目名称:vmtk,代码行数:28,代码来源:vmtkimagefeaturecorrection.py

示例7: subtractionCompare

    def subtractionCompare(self):

        imagePoints = self.Image.GetNumberOfPoints()
        referencePoints = self.ReferenceImage.GetNumberOfPoints()

        self.InputInfo('Image Points: ' + str(imagePoints))
        self.InputInfo('Reference Image Points: ' + str(referencePoints))

        if abs(imagePoints - referencePoints) > 0 :
            self.ResultLog = 'Uneven NumberOfPoints'
            return False
            
        imageScalarType = self.Image.GetScalarType()
        referenceScalarType = self.ReferenceImage.GetScalarType()
        if imageScalarType != referenceScalarType:
            self.PrintError('Error: Input image and reference image are not of \
                the same type. Please cast images to the same type.')

        imageMath = vtk.vtkImageMathematics()
        imageMath.SetInput1Data(self.Image) 
        imageMath.SetInput2Data(self.ReferenceImage) 
        imageMath.SetOperationToSubtract()
        imageMath.Update()
        differenceImage = imageMath.GetOutput()
        differenceRange = differenceImage.GetPointData().GetScalars().GetRange()

        self.InputInfo('Difference Range: ' + str(differenceRange))
 
        if max([abs(d) for d in differenceRange]) < self.Tolerance:
            return True
        
        return False
开发者ID:vmtk,项目名称:vmtk,代码行数:32,代码来源:vmtkimagecompare.py

示例8: __init__

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

示例9: getIndexedImageData

def getIndexedImageData(inputVtkImageData, indexVal):
    """
    @type  inputVtkImageData: C{vtkImageData}
    @param inputVtkImageData: Image data to be processed
    
    @type  indexVal: C{unsigned int}
    @param indexVal: Index value that will be assigned to all non-zero values.
    
    Function replaces all non-zero valued pixels of provided
    C{inputVtkImageData} with C{indexVal} and returns the result.
    
    @rtype: C{vtkImageData}
    @return: UnsignedInt vtkImageData with two values 0 and provided
             C{indexVal}.
    """
    # Convert normalized input image to unsigned int scalars
    cast = vtk.vtkImageCast()
    cast.SetInput(getImageMask(inputVtkImageData))
    cast.SetOutputScalarTypeToUnsignedInt()
    
    # Then multiply the normalized image data by priovided constant
    multip = vtk.vtkImageMathematics()
    multip.SetOperationToMultiplyByK()
    multip.SetConstantK(indexVal)
    multip.SetInput(cast.GetOutput())
    return multip.GetOutput()
开发者ID:pmajka,项目名称:3dbar-extensions,代码行数:26,代码来源:volume_merger.py

示例10: __init__

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


        self._imageMath = vtk.vtkImageMathematics()
        self._imageMath.SetInput1(None)
        self._imageMath.SetInput2(None)
        
        module_utils.setup_vtk_object_progress(self, self._imageMath,
                                           'Performing image math')
        
                                           
        self._config.operation = 'subtract'
        self._config.constantC = 0.0
        self._config.constantK = 1.0


        configList = [
            ('Operation:', 'operation', 'base:str', 'choice',
             'The operation that should be performed.',
             tuple(OPS_DICT.keys())),
            ('Constant C:', 'constantC', 'base:float', 'text',
             'The constant C used in some operations.'),
            ('Constant K:', 'constantK', 'base:float', 'text',
             'The constant C used in some operations.')]

        ScriptedConfigModuleMixin.__init__(
            self, configList,
            {'Module (self)' : self,
             'vtkImageMathematics' : self._imageMath})

        self.sync_module_logic_with_config()
开发者ID:fvpolpeta,项目名称:devide,代码行数:33,代码来源:imageMathematics.py

示例11: test_vtk_pyexception_deadlock

    def test_vtk_pyexception_deadlock(self):
        """Test if VTK has been patched to release the GIL during all
        VTK method calls.
        """

        import vtk
        # this gives floats by default
        s = vtk.vtkImageGridSource()
        c1 = vtk.vtkImageCast()
        c1.SetOutputScalarTypeToShort()
        c1.SetInput(s.GetOutput())
        c2 = vtk.vtkImageCast()
        c2.SetOutputScalarTypeToFloat()
        c2.SetInput(s.GetOutput())

        m = vtk.vtkImageMathematics()

        # make sure we are multi-threaded
        if m.GetNumberOfThreads() < 2:
            m.SetNumberOfThreads(2)
        m.SetInput1(c1.GetOutput())
        m.SetInput2(c2.GetOutput())

        # without the patch, this call will deadlock forever
        try:
            # with the patch this should generate a RuntimeError
            m.Update()
        except RuntimeError:
            pass
        else:
            self.fail(
            'Multi-threaded error vtkImageMathematics did not raise '
            'exception.')
开发者ID:fvpolpeta,项目名称:devide,代码行数:33,代码来源:basic_vtk.py

示例12: _maskSourceExecute

    def _maskSourceExecute(self):
        inputI = self._inputImage
        if inputI:
            inputI.Update()
                
            self._markerSource.Update()
            outputJ = self._markerSource.GetStructuredPointsOutput()
            # we now have an outputJ

            if not inputI.GetScalarPointer() or \
               not outputJ.GetScalarPointer() or \
               not inputI.GetDimensions() > (0,0,0):
                vtk.vtkOutputWindow.GetInstance().DisplayErrorText(
                    'modifyHomotopy: Input is empty.')
                return

            iMath = vtk.vtkImageMathematics()
            iMath.SetOperationToMin()
            iMath.SetInput1(outputJ)
            iMath.SetInput2(inputI)
            iMath.GetOutput().SetUpdateExtentToWholeExtent()
            iMath.Update()

            outputI = self._maskSource.GetStructuredPointsOutput()
            outputI.DeepCopy(iMath.GetOutput())
开发者ID:fvpolpeta,项目名称:devide,代码行数:25,代码来源:modifyHomotopySlow.py

示例13: subtractionCompare

    def subtractionCompare(self):

        imagePoints = self.Image.GetNumberOfPoints()
        referencePoints = self.ReferenceImage.GetNumberOfPoints()

        self.InputInfo('Image Points: ' + str(imagePoints))
        self.InputInfo('Reference Image Points: ' + str(referencePoints))

        if abs(imagePoints - referencePoints) > 0 :
            self.ResultLog = 'Uneven NumberOfPoints'
            return False
            
        imageScalarType = self.Image.GetScalarType()
        referenceScalarType = self.ReferenceImage.GetScalarType()
        minScalarType = min(imageScalarType,referenceScalarType)
        self.Image.SetScalarType(minScalarType) 
        self.ReferenceImage.SetScalarType(minScalarType) 

        imageMath = vtk.vtkImageMathematics()
        imageMath.SetInput1Data(self.Image) 
        imageMath.SetInput2Data(self.ReferenceImage) 
        imageMath.SetOperationToSubtract()
        imageMath.Update()
        differenceImage = imageMath.GetOutput()
        differenceRange = differenceImage.GetPointData().GetScalars().GetRange()

        self.InputInfo('Difference Range: ' + str(differenceRange))
 
        if max([abs(d) for d in differenceRange]) < self.Tolerance:
            return True
        
        return False
开发者ID:samsmu,项目名称:vmtk,代码行数:32,代码来源:vmtkimagecompare.py

示例14: MergeLevelSet

    def MergeLevelSet(self):

        if self.LevelSets == None:
            self.LevelSets = self.LevelSetsOutput
        else:
            minFilter = vtk.vtkImageMathematics()
            minFilter.SetOperationToMin()
            minFilter.SetInput1Data(self.LevelSets)
            minFilter.SetInput2Data(self.LevelSetsOutput)
            minFilter.Update()
            self.LevelSets = minFilter.GetOutput()
开发者ID:vmtk,项目名称:vmtk,代码行数:11,代码来源:vmtklevelsetsegmentation.py

示例15: MergeLevelSets

    def MergeLevelSets(self):

        if self.MergedInitialLevelSets == None:
            self.MergedInitialLevelSets = vtk.vtkImageData()
            self.MergedInitialLevelSets.DeepCopy(self.InitialLevelSets)
        else:
            minFilter = vtk.vtkImageMathematics()
            minFilter.SetOperationToMin()
            minFilter.SetInput1Data(self.MergedInitialLevelSets)
            minFilter.SetInput2Data(self.InitialLevelSets)
            minFilter.Update()
            self.MergedInitialLevelSets = minFilter.GetOutput()
开发者ID:151706061,项目名称:vmtk,代码行数:12,代码来源:vmtkimageinitialization.py


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