VTK中轮廓内区域的提取

2024-09-28 05:34:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在通过vtkContourFilter生成二维轮廓。(见下面的图片)现在我想得到轮廓内的区域,并将其保存为vtkImageData或类似的东西,这将导致一个图像中的数据在轮廓内。其他的都是黑色的,只是为了和切片有相同的尺寸。在

enter image description hereenter image description here

我不知道如何得到轮廓内的区域,有什么办法吗?在

这就是我目前所做的:

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?

提前谢谢。在


Tags: theimage区域图片updatereader轮廓contour
2条回答

vtkContourFilter是一个-在您的案例中-行表示,它不允许任何“内部/外部”过滤。你想要的是vtk.Threshold

threshold = vtk.Threshold()
threshold.SetInputConnection(extractSlice.GetOutputPort())
threshold.ThresholdRange = [37.35310363769531, 276.8288269042969]

上面的代码有些出人意料,这两个标量是应用阈值的最小值和最大值。请看一下Paraview,您可以使用它来组装可视化,并使用Python tracer记录所有内容。这就给您留下了python代码,您可以将它们与普通VTK和python一起使用,这非常好,而且正是您所需要的。但是这样,原型化过程比python更快。在

enter image description here

您应该能够通过使用vtkPolyDataToImageStencil后跟vtkImageStencil来完成此操作,就像在这个例子中一样 http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataContourToImageData

米罗

相关问题 更多 >

    热门问题