本文整理汇总了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()
示例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
示例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()
示例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())
示例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)
示例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()
示例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
示例8: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkImageMathematics(), 'Processing.',
('vtkImageData', 'vtkImageData'), ('vtkImageData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例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()
示例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()
示例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.')
示例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())
示例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
示例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()
示例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()