本文整理汇总了Python中vtk.vtkImageCast函数的典型用法代码示例。如果您正苦于以下问题:Python vtkImageCast函数的具体用法?Python vtkImageCast怎么用?Python vtkImageCast使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkImageCast函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GetRawDICOMData
def GetRawDICOMData(filenames,fileID):
print filenames,fileID
vtkRealDcmReader = vtk.vtkDICOMImageReader()
vtkRealDcmReader.SetFileName("%s/%s"%(rootdir,filenames[0]) )
vtkRealDcmReader.Update()
vtkRealData = vtk.vtkImageCast()
vtkRealData.SetOutputScalarTypeToFloat()
vtkRealData.SetInput( vtkRealDcmReader.GetOutput() )
vtkRealData.Update( )
real_image = vtkRealData.GetOutput().GetPointData()
real_array = vtkNumPy.vtk_to_numpy(real_image.GetArray(0))
vtkImagDcmReader = vtk.vtkDICOMImageReader()
vtkImagDcmReader.SetFileName("%s/%s"%(rootdir,filenames[1]) )
vtkImagDcmReader.Update()
vtkImagData = vtk.vtkImageCast()
vtkImagData.SetOutputScalarTypeToFloat()
vtkImagData.SetInput( vtkImagDcmReader.GetOutput() )
vtkImagData.Update( )
imag_image = vtkImagData.GetOutput().GetPointData()
imag_array = vtkNumPy.vtk_to_numpy(imag_image.GetArray(0))
vtkAppend = vtk.vtkImageAppendComponents()
vtkAppend.SetInput( 0,vtkRealDcmReader.GetOutput() )
vtkAppend.SetInput( 1,vtkImagDcmReader.GetOutput() )
vtkAppend.Update( )
vtkDcmWriter = vtk.vtkDataSetWriter()
vtkDcmWriter.SetFileName("rawdata.%04d.vtk" % fileID )
vtkDcmWriter.SetInput(vtkAppend.GetOutput())
vtkDcmWriter.Update()
return (real_array,imag_array)
开发者ID:ImageGuidedTherapyLab,项目名称:DakotaApplications,代码行数:33,代码来源:tmap.py
示例2: execute
def execute(self, inputs, update = 0, last = 0):
"""
Execute the filter with given inputs and return the output
"""
if not lib.ProcessingFilter.ProcessingFilter.execute(self, inputs):
return None
image = self.getInput(1)
origType = image.GetScalarType()
cast1 = vtk.vtkImageCast()
cast1.SetInput(image)
cast1.SetOutputScalarTypeToShort()
# vtkImageCityBlockDistance requires short input
self.vtkfilter.SetInput(cast1.GetOutput())
data = self.vtkfilter.GetOutput()
if self.parameters["CastToOriginal"]:
cast = vtk.vtkImageCast()
cast.SetInput(self.vtkfilter.GetOutput())
cast.SetOutputScalarType(origType)
cast.SetClampOverflow(1)
data = cast.GetOutput()
if update:
self.vtkfilter.Update()
return data
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:27,代码来源:CityBlockDistance.py
示例3: 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
示例4: onApply
def onApply(self):
# TODO:
# self.logic.undoRedo = self.undoRedo
# Get parameters
fullyConnected = self.scriptedEffect.integerParameter("FullyConnected")
minimumSize = self.scriptedEffect.integerParameter("MinimumSize")
# Get modifier labelmap
selectedSegmentLabelmap = self.scriptedEffect.selectedSegmentLabelmap()
castIn = vtk.vtkImageCast()
castIn.SetInputData(selectedSegmentLabelmap)
castIn.SetOutputScalarTypeToUnsignedLong()
# Identify the islands in the inverted volume and
# find the pixel that corresponds to the background
islandMath = vtkITK.vtkITKIslandMath()
islandMath.SetInputConnection(castIn.GetOutputPort())
islandMath.SetFullyConnected(fullyConnected)
islandMath.SetMinimumSize(minimumSize)
# Note that island operation happens in unsigned long space
# but the segment editor works in unsigned char
castOut = vtk.vtkImageCast()
castOut.SetInputConnection(islandMath.GetOutputPort())
castOut.SetOutputScalarTypeToUnsignedChar()
castOut.Update()
islandCount = islandMath.GetNumberOfIslands()
islandOrigCount = islandMath.GetOriginalNumberOfIslands()
ignoredIslands = islandOrigCount - islandCount
logging.info("%d islands created (%d ignored)" % (islandCount, ignoredIslands))
# Create oriented image data from output
import vtkSegmentationCorePython as vtkSegmentationCore
multiLabelImage = vtkSegmentationCore.vtkOrientedImageData()
multiLabelImage.DeepCopy(castOut.GetOutput())
selectedSegmentLabelmapImageToWorldMatrix = vtk.vtkMatrix4x4()
selectedSegmentLabelmap.GetImageToWorldMatrix(selectedSegmentLabelmapImageToWorldMatrix)
multiLabelImage.SetGeometryFromImageToWorldMatrix(selectedSegmentLabelmapImageToWorldMatrix)
# Import multi-label labelmap to segmentation
segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
selectedSegmentID = self.scriptedEffect.parameterSetNode().GetSelectedSegmentID()
selectedSegmentName = segmentationNode.GetSegmentation().GetSegment(selectedSegmentID).GetName()
slicer.vtkSlicerSegmentationsModuleLogic.ImportLabelmapToSegmentationNode(
multiLabelImage, segmentationNode, selectedSegmentName
)
# Set labelmap visibility to outline for the new segments
displayNode = segmentationNode.GetDisplayNode()
# for index in xrange(1,islandCount+1):
# segmentID = selectedSegmentName + "_" + str(index)
# displayNode.SetSegmentVisibility2DFill(segmentID, False)
# displayNode.SetSegmentVisibility2DOutline(segmentID, True)
displayNode.SetSegmentVisibility(selectedSegmentID, False)
开发者ID:ZeneticX,项目名称:Slicer,代码行数:59,代码来源:SegmentEditorIdentifyIslandsEffect.py
示例5: onApply
def onApply(self):
# This can be a long operation - indicate it to the user
qt.QApplication.setOverrideCursor(qt.Qt.WaitCursor)
self.scriptedEffect.saveStateForUndo()
# Get parameters
fullyConnected = self.scriptedEffect.integerParameter("FullyConnected")
minimumSize = self.scriptedEffect.integerParameter("MinimumSize")
# Get modifier labelmap
selectedSegmentLabelmap = self.scriptedEffect.selectedSegmentLabelmap()
castIn = vtk.vtkImageCast()
castIn.SetInputData(selectedSegmentLabelmap)
castIn.SetOutputScalarTypeToUnsignedLong()
# Identify the islands in the inverted volume and
# find the pixel that corresponds to the background
islandMath = vtkITK.vtkITKIslandMath()
islandMath.SetInputConnection(castIn.GetOutputPort())
islandMath.SetFullyConnected(fullyConnected)
islandMath.SetMinimumSize(minimumSize)
# Note that island operation happens in unsigned long space
# but the segment editor works in unsigned char
castOut = vtk.vtkImageCast()
castOut.SetInputConnection(islandMath.GetOutputPort())
castOut.SetOutputScalarTypeToUnsignedChar()
castOut.Update()
islandCount = islandMath.GetNumberOfIslands()
islandOrigCount = islandMath.GetOriginalNumberOfIslands()
ignoredIslands = islandOrigCount - islandCount
logging.info( "%d islands created (%d ignored)" % (islandCount, ignoredIslands) )
# Create oriented image data from output
import vtkSegmentationCorePython as vtkSegmentationCore
multiLabelImage = vtkSegmentationCore.vtkOrientedImageData()
multiLabelImage.DeepCopy(castOut.GetOutput())
selectedSegmentLabelmapImageToWorldMatrix = vtk.vtkMatrix4x4()
selectedSegmentLabelmap.GetImageToWorldMatrix(selectedSegmentLabelmapImageToWorldMatrix)
multiLabelImage.SetGeometryFromImageToWorldMatrix(selectedSegmentLabelmapImageToWorldMatrix)
# Import multi-label labelmap to segmentation
segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
selectedSegmentID = self.scriptedEffect.parameterSetNode().GetSelectedSegmentID()
selectedSegmentName = segmentationNode.GetSegmentation().GetSegment(selectedSegmentID).GetName()
slicer.vtkSlicerSegmentationsModuleLogic.ImportLabelmapToSegmentationNode( \
multiLabelImage, segmentationNode, selectedSegmentName )
segmentationNode.GetSegmentation().RemoveSegment(selectedSegmentID)
qt.QApplication.restoreOverrideCursor()
开发者ID:MayeulChassagnard,项目名称:Slicer,代码行数:54,代码来源:SegmentEditorIdentifyIslandsEffect.py
示例6: GetRawDICOMData
def GetRawDICOMData(filenames,fileID):
print filenames,fileID
vtkRealDcmReader = vtk.vtkDICOMImageReader()
vtkRealDcmReader.SetFileName("%s/%s"%(rootdir,filenames[0]) )
vtkRealDcmReader.Update()
vtkRealData = vtk.vtkImageCast()
vtkRealData.SetOutputScalarTypeToFloat()
vtkRealData.SetInput( vtkRealDcmReader.GetOutput() )
vtkRealData.Update( )
real_image = vtkRealData.GetOutput().GetPointData()
real_array = vtkNumPy.vtk_to_numpy(real_image.GetArray(0))
vtkImagDcmReader = vtk.vtkDICOMImageReader()
vtkImagDcmReader.SetFileName("%s/%s"%(rootdir,filenames[1]) )
vtkImagDcmReader.Update()
vtkImagData = vtk.vtkImageCast()
vtkImagData.SetOutputScalarTypeToFloat()
vtkImagData.SetInput( vtkImagDcmReader.GetOutput() )
vtkImagData.Update( )
imag_image = vtkImagData.GetOutput().GetPointData()
imag_array = vtkNumPy.vtk_to_numpy(imag_image.GetArray(0))
vtkAppend = vtk.vtkImageAppendComponents()
vtkAppend.SetInput( 0,vtkRealDcmReader.GetOutput() )
vtkAppend.SetInput( 1,vtkImagDcmReader.GetOutput() )
vtkAppend.Update( )
# write raw data
vtkRawData = vtkAppend.GetOutput()
vtkRawData.SetSpacing( spacing )
vtkDcmWriter = vtk.vtkDataSetWriter()
vtkDcmWriter.SetFileTypeToBinary()
vtkDcmWriter.SetFileName("s%d/rawdata.%04d.vtk" % (dirID,fileID) )
vtkDcmWriter.SetInput( vtkRawData )
vtkDcmWriter.Update()
# write raw phase data
vtkPhase = vtk.vtkImageMathematics()
vtkPhase.SetInput1( vtkRealData.GetOutput() )
vtkPhase.SetInput2( vtkImagData.GetOutput() )
vtkPhase.SetOperationToATAN2( )
vtkPhase.Update( )
vtkPhaseData = vtkPhase.GetOutput()
vtkPhaseData.SetSpacing( spacing )
vtkDcmWriter = vtk.vtkDataSetWriter()
vtkDcmWriter.SetFileTypeToBinary()
vtkDcmWriter.SetFileName("s%d/phase.%04d.vtk" % (dirID,fileID) )
vtkDcmWriter.SetInput( vtkPhaseData)
vtkDcmWriter.Update()
return (real_array,imag_array)
开发者ID:ImageGuidedTherapyLab,项目名称:MotionCorrection,代码行数:51,代码来源:tmap.py
示例7: removeIslands
def removeIslands(self):
#
# change the label values based on the parameter node
#
if not self.sliceLogic:
self.sliceLogic = self.editUtil.getSliceLogic()
parameterNode = self.editUtil.getParameterNode()
minimumSize = int(parameterNode.GetParameter("IslandEffect,minimumSize"))
fullyConnected = bool(parameterNode.GetParameter("IslandEffect,fullyConnected"))
label = self.editUtil.getLabel()
# note that island operation happens in unsigned long space
# but the slicer editor works in Short
castIn = vtk.vtkImageCast()
if vtk.VTK_MAJOR_VERSION <= 5:
castIn.SetInput( self.getScopedLabelInput() )
else:
castIn.SetInputData( self.getScopedLabelInput() )
castIn.SetOutputScalarTypeToUnsignedLong()
# now identify the islands in the inverted volume
# and find the pixel that corresponds to the background
islandMath = vtkITK.vtkITKIslandMath()
if vtk.VTK_MAJOR_VERSION <= 5:
islandMath.SetInput( castIn.GetOutput() )
else:
islandMath.SetInputConnection( castIn.GetOutputPort() )
islandMath.SetFullyConnected( fullyConnected )
islandMath.SetMinimumSize( minimumSize )
# TODO: $this setProgressFilter $islandMath "Calculating Islands..."
# note that island operation happens in unsigned long space
# but the slicer editor works in Short
castOut = vtk.vtkImageCast()
if vtk.VTK_MAJOR_VERSION <= 5:
castOut.SetInput( islandMath.GetOutput() )
else:
castOut.SetInputConnection( islandMath.GetOutputPort() )
castOut.SetOutputScalarTypeToShort()
castOut.SetOutput( self.getScopedLabelOutput() )
# TODO $this setProgressFilter $postThresh "Applying to Label Map..."
castOut.Update()
islandCount = islandMath.GetNumberOfIslands()
islandOrigCount = islandMath.GetOriginalNumberOfIslands()
ignoredIslands = islandOrigCount - islandCount
print( "%d islands created (%d ignored)" % (islandCount, ignoredIslands) )
self.applyScopedLabel()
castOut.SetOutput( None )
开发者ID:kingofpanda,项目名称:Slicer,代码行数:50,代码来源:IdentifyIslandsEffect.py
示例8: castImagesToLargestDataType
def castImagesToLargestDataType(images):
"""
This function casts a list of images using the vtkImageCast so that they all have the
same type that is large enough to hold all of the images
@param images A list of vtkImageData objects
"""
returnValues = []
largestType = -1
largestMax = 0
types = []
differ = 0
for index, i in enumerate(images):
types.append(i.GetScalarType())
if types[index] != types[index - 1]:
differ = 1
if i.GetScalarTypeMax() > largestMax:
largestType = i.GetScalarType()
largestMax = i.GetScalarTypeMax()
if not differ:
return images
for i, image in enumerate(images):
cast = vtk.vtkImageCast()
cast.SetOutputScalarType(largestType)
cast.SetInput(image)
image = cast.GetOutput()
returnValues.append(image)
return returnValues
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:30,代码来源:ImageOperations.py
示例9: run
def run(self):
global vtk_error
#----- verify extension ------------------
extension = VerifyDataType(self.filepath)
file_name = self.filepath.split(os.path.sep)[-1]
n_array = ReadBitmap(self.filepath)
if not(isinstance(n_array, numpy.ndarray)):
return False
image = converters.to_vtk(n_array, spacing=(1,1,1),\
slice_number=1, orientation="AXIAL")
dim = image.GetDimensions()
x = dim[0]
y = dim[1]
img = vtk.vtkImageResample()
img.SetInputData(image)
img.SetAxisMagnificationFactor ( 0, 0.25 )
img.SetAxisMagnificationFactor ( 1, 0.25 )
img.SetAxisMagnificationFactor ( 2, 1 )
img.Update()
tp = img.GetOutput().GetScalarTypeAsString()
image_copy = vtk.vtkImageData()
image_copy.DeepCopy(img.GetOutput())
thumbnail_path = tempfile.mktemp()
write_png = vtk.vtkPNGWriter()
write_png.SetInputConnection(img.GetOutputPort())
write_png.AddObserver("WarningEvent", VtkErrorPNGWriter)
write_png.SetFileName(thumbnail_path)
write_png.Write()
if vtk_error:
img = vtk.vtkImageCast()
img.SetInputData(image_copy)
img.SetOutputScalarTypeToUnsignedShort()
#img.SetClampOverflow(1)
img.Update()
write_png = vtk.vtkPNGWriter()
write_png.SetInputConnection(img.GetOutputPort())
write_png.SetFileName(thumbnail_path)
write_png.Write()
vtk_error = False
id = wx.NewId()
bmp_item = [self.filepath, thumbnail_path, extension, x, y,\
str(x) + ' x ' + str(y), file_name, id]
self.bmp_file.Add(bmp_item)
开发者ID:invesalius,项目名称:invesalius3,代码行数:60,代码来源:bitmap_reader.py
示例10: castVolumeNodeToShort
def castVolumeNodeToShort(self, volumeNode):
imageData = volumeNode.GetImageData()
cast=vtk.vtkImageCast()
cast.SetInputData(imageData)
cast.SetOutputScalarTypeToShort()
cast.SetOutput(imageData)
cast.Update()
开发者ID:gti-fing,项目名称:SlicerEpilepsyToolkit,代码行数:7,代码来源:AContrarioLogic.py
示例11: 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
示例12: 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
示例13: BuildUpwindGradientBasedFeatureImage
def BuildUpwindGradientBasedFeatureImage(self):
cast = vtk.vtkImageCast()
cast.SetInputData(self.Image)
cast.SetOutputScalarTypeToFloat()
cast.Update()
gradientMagnitude = vtkvmtk.vtkvmtkUpwindGradientMagnitudeImageFilter()
gradientMagnitude.SetInputConnection(cast.GetOutputPort())
gradientMagnitude.SetUpwindFactor(self.UpwindFactor)
gradientMagnitude.Update()
featureImage = None
if self.SigmoidRemapping==1:
scalarRange = gradientMagnitude.GetOutput().GetPointData().GetScalars().GetRange()
inputMinimum = scalarRange[0]
inputMaximum = scalarRange[1]
alpha = - (inputMaximum - inputMinimum) / 6.0
beta = (inputMaximum + inputMinimum) / 2.0
sigmoid = vtkvmtk.vtkvmtkSigmoidImageFilter()
sigmoid.SetInputConnection(gradientMagnitude.GetOutputPort())
sigmoid.SetAlpha(alpha)
sigmoid.SetBeta(beta)
sigmoid.SetOutputMinimum(0.0)
sigmoid.SetOutputMaximum(1.0)
sigmoid.Update()
featureImage = sigmoid.GetOutput()
else:
boundedReciprocal = vtkvmtk.vtkvmtkBoundedReciprocalImageFilter()
boundedReciprocal.SetInputConnection(gradientMagnitude.GetOutputPort())
boundedReciprocal.Update()
featureImage = boundedReciprocal.GetOutput()
self.FeatureImage = vtk.vtkImageData()
self.FeatureImage.DeepCopy(featureImage)
开发者ID:vmtk,项目名称:vmtk,代码行数:35,代码来源:vmtkimagefeatures.py
示例14: execute
def execute(self, inputs, update = 0, last = 0):
"""
Execute the filter with given inputs and return the output
"""
lib.ProcessingFilter.ProcessingFilter.execute(self, inputs)
image = self.getInput(1)
image2 = self.getInput(2)
self.vtkfilter.SetClampOverflow(self.parameters["ClampOverflow"])
if self.numberOfInputs[0] > 1:
if image.GetScalarType != image2.GetScalarType():
cast = vtk.vtkImageCast()
cast.SetOutputScalarType(image.GetScalarType())
cast.SetInput(image2)
cast.Update()
image2 = cast.GetOutput()
self.vtkfilter.SetInput1(image)
self.vtkfilter.SetInput2(image2)
else:
self.vtkfilter.SetInput1(image)
self.vtkfilter.SetInput2(image)
self.vtkfilter.SetInput(image)
f = "self.vtkfilter.SetOperationTo%s()" % self.operation
eval(f)
if update:
self.vtkfilter.Update()
return self.vtkfilter.GetOutput()
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:28,代码来源:MathFilters.py
示例15: Execute
def Execute(self):
if self.Image == None:
self.PrintError('Error: No input image.')
if self.OutputType == 'uchar' and self.ShiftScale:
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInputData(self.Image)
if self.WindowLevel[0] == 0.0:
scalarRange = self.Image.GetScalarRange()
scale = 255.0
if (scalarRange[1]-scalarRange[0]) > 0.0:
scale = 255.0/(scalarRange[1]-scalarRange[0])
shiftScale.SetShift(-scalarRange[0])
shiftScale.SetScale(scale)
else:
shiftScale.SetShift(-(self.WindowLevel[1]-self.WindowLevel[0]/2.0))
shiftScale.SetScale(255.0/self.WindowLevel[0])
shiftScale.SetOutputScalarTypeToUnsignedChar()
shiftScale.ClampOverflowOn()
shiftScale.Update()
self.Image = shiftScale.GetOutput()
else:
cast = vtk.vtkImageCast()
cast.SetInputData(self.Image)
if self.OutputType == 'float':
cast.SetOutputScalarTypeToFloat()
elif self.OutputType == 'double':
cast.SetOutputScalarTypeToDouble()
elif self.OutputType == 'uchar':
cast.SetOutputScalarTypeToUnsignedChar()
elif self.OutputType == 'short':
cast.SetOutputScalarTypeToShort()
cast.Update()
self.Image = cast.GetOutput()
开发者ID:samsmu,项目名称:vmtk,代码行数:35,代码来源:vmtkimagecast.py
示例16: read_metaimage
def read_metaimage(self, fname_meta, cast_type=5):
reader = vtk.vtkMetaImageReader()
reader.SetFileName(fname_meta)
# VTK image cast
img_cast = vtk.vtkImageCast()
if cast_type == 0:
# return a vtkImageData with wrong dims and bounds value
self.reader = reader.GetOutput()
# return reader.GetOutput()
elif cast_type in [i for i in range(2, 12)]:
img_cast.SetInputConnection(reader.GetOutputPort())
img_cast.SetOutputScalarType(cast_type)
img_cast.Update()
self.reader = img_cast.GetOutput()
# return img_cast.GetOutput() # a vtkImageData
else:
sys.stderr.write(
('Wrong Cast Type! It should be 2, 3, ..., 11\n')
('No Image Cast Applied')
)
self.reader = img_cast.GetOutput()
# return reader.GetOutput()
self.flag_read = True
return self.reader
开发者ID:quentan,项目名称:Work_Test_4,代码行数:30,代码来源:medical_object.py
示例17: onApply
def onApply(self):
inputVolume = self.inputSelector.currentNode()
outputVolume = self.outputSelector.currentNode()
if not (inputVolume):
qt.QMessageBox.critical(
slicer.util.mainWindow(),
'Averaging', 'Input volumes are required')
return
outVolumeNode = self.outputSelector.currentNode()
volumesLogic = slicer.modules.volumes.logic()
# newNode = volumesLogic.CloneVolume(slicer.mrmlScene, sourceVolumeNode, 'average volume')
# create output volume by cloning the selected reference volume
# volumesLogic = slicer.modules.volumes.logic()
newNode = volumesLogic.CloneVolume(self.inputSelector.currentNode(), "average volume")
# vtk function to average the images
imgsum = vtk.vtkImageWeightedSum()
imgsum.NormalizeByWeightOn()
# add all of the input image data
for (i,n) in enumerate(self.inputSelector.checkedNodes()):
print("adding input image: {0}".format(n.GetName()))
cast = vtk.vtkImageCast()
cast.SetOutputScalarTypeToFloat()
cast.AddInputConnection(n.GetImageDataConnection())
imgsum.AddInputConnection(cast.GetOutputPort())
imgsum.SetWeight(i, 1.)
# run the filter and set the result to the output image
imgsum.Update()
newNode.SetAndObserveImageData(imgsum.GetOutput())
开发者ID:ysuter,项目名称:new-modules,代码行数:35,代码来源:avg_selected_images.py
示例18: execute
def execute(self, inputs = (1,1), update = 0, last = 0):
"""
Execute filter in input image and return output image
"""
if not lib.ProcessingFilter.ProcessingFilter.execute(self,inputs):
return None
self.eventDesc = "Calculating FFT"
inputImage = self.getInput(1)
# Convert image to float
origType = inputImage.GetScalarType()
castFloat = vtk.vtkImageCast()
castFloat.SetOutputScalarTypeToFloat()
self.filter = vtk.vtkImageFFT()
#magnitude = vtk.vtkImageMagnitude()
#fourierCenter = vtk.vtkImageFourierCenter()
#logarithmic = vtk.vtkImageLogarithmicScale()
#logarithmic.SetConstant(15)
castFloat.SetInput(inputImage)
self.filter.SetInputConnection(castFloat.GetOutputPort())
#magnitude.SetInputConnection(self.filter.GetOutputPort())
#fourierCenter.SetInputConnection(magnitude.GetOutputPort())
#logarithmic.SetInputConnection(fourierCenter.GetOutputPort())
#outputImage = logarithmic.GetOutput()
outputImage = self.filter.GetOutput()
if update:
outputImage.Update()
return outputImage
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:32,代码来源:FFT.py
示例19: Execute
def Execute(self):
if self.Image == None:
self.PrintError('Error: No input image.')
morphologyFilter = vtkvmtk.vtkvmtkGrayscaleMorphologyImageFilter()
if self.Operation == 'close':
morphologyFilter.SetOperationToClose()
elif self.Operation == 'open':
morphologyFilter.SetOperationToOpen()
elif self.Operation == 'dilate':
morphologyFilter.SetOperationToDilate()
elif self.Operation == 'erode':
morphologyFilter.SetOperationToErode()
cast = vtk.vtkImageCast()
cast.SetInputData(self.Image)
cast.SetOutputScalarTypeToFloat()
cast.Update()
morphologyFilter.SetInputConnection(cast.GetOutputPort())
morphologyFilter.SetBallRadius(self.BallRadius)
morphologyFilter.Update()
self.Image = morphologyFilter.GetOutput()
开发者ID:vmtk,项目名称:vmtk,代码行数:25,代码来源:vmtkimagemorphology.py
示例20: convertITKtoVTK
def convertITKtoVTK(self, image, cast = None, force = 0):
"""
Convert the ITK image data to VTK image
"""
# For non-ITK images, do nothing
if image.__class__ == vtk.vtkImageData:
return image
try:
import itk
except ImportError:
print "Could not import ITK, terminating."
sys.exit()
self.itkToVtk = itk.ImageToVTKImageFilter[image].New()
# If the next filter is also an ITK filter, then won't
# convert
if not force and self.nextFilter and self.nextFilter.getITK():
return image
self.itkToVtk.SetInput(image)
self.itkToVtk.Update()
if cast:
icast = vtk.vtkImageCast()
if cast == "UC3":
icast.SetOutputScalarTypeToUnsignedChar()
elif cast == "US3":
icast.SetOutputScalarTypeToUnsignedShort()
icast.SetInput(self.itkToVtk.GetOutput())
icast.Update()
return icast.GetOutput()
return self.itkToVtk.GetOutput()
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:34,代码来源:ProcessingFilter.py
注:本文中的vtk.vtkImageCast函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论