In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use Python VTK to complete image cutting" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "how to use Python VTK to complete image cutting" article can help you solve the problem.
1. Read the two-dimensional picture sequence to complete the surface drawing.
For more information, see Python-VTK to read 2D slices and display 3D models in batches.
2. Introduction to vtk.vtkOutlineFilter ()
This space is equivalent to generating the outline of the rendered model, for example, if the 3D image size is (256x256x200), then this control will generate a box frame with a length, width and height of 256x256x200.
Details: VTK official document
3. Implicit function plane module vtk.vtkImplicitPlaneWidget ()
Using this module, you can flexibly adjust the plane vtkImplicitPlaneWidget official documents that need to be selected.
4. Vtk.vtkClipPolyData ()
The cutting result of vtkclippolydata is divided into upper and lower parts according to the tangent plane normal, and there is a corresponding output interface in the interface.
VtkClipPolyData official documentation
Display of cutting effect
The code is as follows:
Import vtkdef main (): arender = vtk.vtkRenderer () arender.SetViewport (0,0.0,0.5) RenWin = vtk.vtkRenderWindow () renWin.AddRenderer (arender) iren = vtk.vtkRenderWindowInteractor () iren.SetRenderWindow (renWin) # Reader = vtk.vtkMetaImageReader () # Reader.SetFileName ("bbb.mhd") # Reader.Update () # read pictures, surface rendering Reader = vtk.vtkPNGReader () Reader.SetNumberOfScalarComponents (1) Reader.GetOutput (). GetOrigin () Reader.SetDataByteOrderToLittleEndian () Reader.SetFileDimensionality (3) Reader.SetDataExtent (0512 0512j0226) Reader.SetFilePrefix ("E:/qct_data/in_out_data/in_data/inner/label/22/") # Reader.SetFilePrefix ("C:/Users/deng5/Desktop/2/48/") Reader.SetFilePattern ("% s%d.png") Reader.SetDataSpacing (1,1,1) # Volume Pixel Reader.Update () # Surface drawing Code For more information, please see the article skinExtractor = vtk.vtkContourFilter () skinExtractor.SetInputConnection (Reader.GetOutputPort ()) skinExtractor.SetValue (0,1) skinExtractor.ComputeGradientsOn () SkinExtractor.ComputeScalarsOn () Smooth = vtk.vtkSmoothPolyDataFilter () smooth.SetInputConnection (skinExtractor.GetOutputPort ()) smooth.SetNumberOfIterations (100) skinNormals = vtk.vtkPolyDataNormals () skinNormals.SetInputConnection (smooth.GetOutputPort ()) skinNormals.SetFeatureAngle (50) skinStripper = vtk.vtkStripper () skinStripper.SetInputConnection (skinNormals.GetOutputPort ()) skinMapper = vtk.vtkPolyDataMapper () skinMapper.SetInputConnection (skinStripper.GetOutputPort ()) skinMapper.ScalarVisibilityOff () skin = vtk.vtkActor () skin. SetMapper (skinMapper) # defines an image boundary control outlineData = vtk.vtkOutlineFilter () outlineData.SetInputConnection (Reader.GetOutputPort ()) mapOutline = vtk.vtkPolyDataMapper () mapOutline.SetInputConnection (outlineData.GetOutputPort ()) outline = vtk.vtkActor () outline.SetMapper (mapOutline) outline.GetProperty () .SetColor (0 0,0) aCamera = vtk.vtkCamera () aCamera.SetViewUp (0,0,-1) aCamera.SetPosition (0,1) 0) aCamera.ComputeViewPlaneNormal () aCamera.Azimuth (30.0) aCamera.Elevation (30.0) aCamera.Dolly (1.5) arender.AddActor (outline) arender.AddActor (skin) # splineActor.GetProperty (). SetLineWidth (5) # arender.AddActor (splineActor) # arender.AddActor (pointActor) arender.SetActiveCamera (aCamera) arender.ResetCamera () arender.SetBackground (.2, .3 .4) arender.ResetCameraClippingRange () renWin.SetSize (1000, 1000) style = vtk.vtkInteractorStyleTrackballCamera () iren.SetInteractorStyle (style) # define cutter global cliper cliper = vtk.vtkClipPolyData () cliper.SetInputData (skinStripper.GetOutput ()) # define plane hidden function implicitPlaneWidget = vtk.vtkImplicitPlaneWidget () implicitPlaneWidget.SetInteractor (iren) implicitPlaneWidget.SetPlaceFactor (1.25) implicitPlaneWidget.SetInputData (skinStripper.GetOutput ()) implicitPlaneWidget.PlaceWidget () global coneSkinActor coneSkinActor = vtk.vtkActor () coneSkinActor.SetMapper (skinMapper) rRenderer = vtk.vtkRenderer () rRenderer.SetBackground (0.2,0.3) 0.5) rRenderer.SetViewport (0.5,0.0,1.0,1.0) coneSkinActor.RotateZ (90) rRenderer.AddActor (coneSkinActor) renWin.AddRenderer (rRenderer) # Associated CallBack function implicitPlaneWidget.AddObserver ("EndInteractionEvent", my_call_back) implicitPlaneWidget.On () renWin.Render () iren.Initialize () iren.Start () # CallBack function def my_call_back (pWidget,ev): # indicates when the pWidget control changes Trigger function if (pWidget): print (pWidget.GetClassName (), "Event Id:", ev) planeNew = vtk.vtkPlane () # get the plane in pWidget, assign the plane value to planeNew pWidget.GetPlane (planeNew) # cliper, set the plane of the clipper cliper to planeNew cliper.SetClipFunction (planeNew) planeNew.GetNormal () cliper.Update () # pass the reduced model to another window clipedData = vtk.vtkPolyData () clipedData.DeepCopy (cliper.GetOutput ()) coneMapper = vtk.vtkPolyDataMapper () coneMapper.SetInputData (clipedData) coneMapper.ScalarVisibilityOff () coneSkinActor.SetMapper (coneMapper) print ("Plane Normal =" + str (planeNew.GetNormal () print ("Plane Origin =" + str (planeNew. GetOrigin ()) main () on "how to use Python VTK to complete image cutting" is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 254
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.