本文整理汇总了Python中EditUtil.EditUtil.getBackgroundImage方法的典型用法代码示例。如果您正苦于以下问题:Python EditUtil.getBackgroundImage方法的具体用法?Python EditUtil.getBackgroundImage怎么用?Python EditUtil.getBackgroundImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EditUtil.EditUtil
的用法示例。
在下文中一共展示了EditUtil.getBackgroundImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fastMarching
# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import getBackgroundImage [as 别名]
def fastMarching(self,percentMax):
self.fm = None
# allocate a new filter each time March is hit
bgImage = EditUtil.getBackgroundImage()
labelImage = EditUtil.getLabelImage()
# collect seeds
if vtk.VTK_MAJOR_VERSION <= 5:
dim = bgImage.GetWholeExtent()
else:
dim = bgImage.GetDimensions()
print dim
# initialize the filter
self.fm = slicer.vtkPichonFastMarching()
scalarRange = bgImage.GetScalarRange()
depth = scalarRange[1]-scalarRange[0]
# this is more or less arbitrary; large depth values will bring the
# algorithm to the knees
scaleValue = 0
shiftValue = 0
if depth>300:
scaleValue = 300./depth
if scalarRange[0] < 0:
shiftValue = scalarRange[0]*-1
if scaleValue or shiftValue:
rescale = vtk.vtkImageShiftScale()
if vtk.VTK_MAJOR_VERSION <= 5:
rescale.SetInput(bgImage)
else:
rescale.SetInputData(bgImage)
rescale.SetScale(scaleValue)
rescale.SetShift(shiftValue)
rescale.Update()
bgImage = rescale.GetOutput()
scalarRange = bgImage.GetScalarRange()
depth = scalarRange[1]-scalarRange[0]
print('Input scalar range: '+str(depth))
if vtk.VTK_MAJOR_VERSION <= 5:
self.fm.init(dim[1]+1, dim[3]+1, dim[5]+1, depth, 1, 1, 1)
else:
self.fm.init(dim[0], dim[1], dim[2], depth, 1, 1, 1)
caster = vtk.vtkImageCast()
caster.SetOutputScalarTypeToShort()
if vtk.VTK_MAJOR_VERSION <= 5:
caster.SetInput(bgImage)
caster.Update()
self.fm.SetInput(caster.GetOutput())
else:
caster.SetInputData(bgImage)
self.fm.SetInputConnection(caster.GetOutputPort())
# self.fm.SetOutput(labelImage)
if vtk.VTK_MAJOR_VERSION <= 5:
npoints = int((dim[1]+1)*(dim[3]+1)*(dim[5]+1)*percentMax/100.)
else:
npoints = int(dim[0]*dim[1]*dim[2]*percentMax/100.)
self.fm.setNPointsEvolution(npoints)
print('Setting active label to '+str(EditUtil.getLabel()))
self.fm.setActiveLabel(EditUtil.getLabel())
nSeeds = self.fm.addSeedsFromImage(labelImage)
if nSeeds == 0:
return 0
self.fm.Modified()
self.fm.Update()
# TODO: need to call show() twice for data to be updated
self.fm.show(1)
self.fm.Modified()
self.fm.Update()
self.fm.show(1)
self.fm.Modified()
self.fm.Update()
self.undoRedo.saveState()
EditUtil.getLabelImage().DeepCopy(self.fm.GetOutput())
EditUtil.markVolumeNodeAsModified(self.sliceLogic.GetLabelLayer().GetVolumeNode())
# print('FastMarching output image: '+str(output))
print('FastMarching march update completed')
return npoints