我正在通过vtkContourFilter
生成二维轮廓。(见下面的图片)现在我想得到轮廓内的区域,并将其保存为vtkImageData
或类似的东西,这将导致一个图像中的数据在轮廓内。其他的都是黑色的,只是为了和切片有相同的尺寸。在
我不知道如何得到轮廓内的区域,有什么办法吗?在
这就是我目前所做的:
import vtk
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName("sample.vti")
reader.GetOutput().SetUpdateExtentToWholeExtent()
reader.Update()
flipYFilter = vtk.vtkImageFlip()
flipYFilter.SetFilteredAxis(1)
flipYFilter.SetInput(reader.GetOutput())
flipYFilter.Update()
image = flipYFilter.GetOutput()
extractSlice = vtk.vtkExtractVOI()
extractSlice.SetInput(image)
extractSlice.SetVOI(image.GetExtent()[0], image.GetExtent()[1], \
image.GetExtent()[2], image.GetExtent()[3], \
5, 5)
extractSlice.SetSampleRate(1, 1, 1)
extractSlice.Update()
contour = vtk.vtkContourFilter()
contour.SetInputConnection(extractSlice.GetOutputPort())
contour.SetValue(1,90)
#How to get the region inside the contour?
提前谢谢。在
vtkContourFilter
是一个-在您的案例中-行表示,它不允许任何“内部/外部”过滤。你想要的是vtk.Threshold
上面的代码有些出人意料,这两个标量是应用阈值的最小值和最大值。请看一下Paraview,您可以使用它来组装可视化,并使用Python tracer记录所有内容。这就给您留下了python代码,您可以将它们与普通VTK和python一起使用,这非常好,而且正是您所需要的。但是这样,原型化过程比python更快。在
您应该能够通过使用
vtkPolyDataToImageStencil
后跟vtkImageStencil
来完成此操作,就像在这个例子中一样 http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataContourToImageData嗯
米罗
相关问题 更多 >
编程相关推荐