def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkImageNonMaximumSuppression(), 'Processing.', ('vtkImageData', 'vtkImageData'), ('vtkImageData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkImageNonMaximumSuppression(), 'Processing.', ('vtkImageData', 'vtkImageData'), ('vtkImageData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
ic.SetOutputScalarTypeToFloat() ic.SetInputConnection(il.GetOutputPort()) # smooth the image gs = vtk.vtkImageGaussianSmooth() gs.SetInputConnection(ic.GetOutputPort()) gs.SetDimensionality(2) gs.SetRadiusFactors(1, 1, 0) # gradient the image imgGradient = vtk.vtkImageGradient() imgGradient.SetInputConnection(gs.GetOutputPort()) imgGradient.SetDimensionality(2) imgMagnitude = vtk.vtkImageMagnitude() imgMagnitude.SetInputConnection(imgGradient.GetOutputPort()) imgMagnitude.Update() # non maximum suppression nonMax = vtk.vtkImageNonMaximumSuppression() nonMax.SetMagnitudeInputData(imgMagnitude.GetOutput()) nonMax.SetVectorInputData(imgGradient.GetOutput()) nonMax.SetDimensionality(2) pad = vtk.vtkImageConstantPad() pad.SetInputConnection(imgGradient.GetOutputPort()) pad.SetOutputNumberOfScalarComponents(3) pad.SetConstant(0) pad.Update() i2sp1 = vtk.vtkImageToStructuredPoints() i2sp1.SetInputConnection(nonMax.GetOutputPort()) i2sp1.SetVectorInputData(pad.GetOutput()) # link edgles imgLink = vtk.vtkLinkEdgels() imgLink.SetInputConnection(i2sp1.GetOutputPort()) imgLink.SetGradientThreshold(2)
ic.SetOutputScalarTypeToFloat() ic.SetInputConnection(il.GetOutputPort()) # smooth the image gs = vtk.vtkImageGaussianSmooth() gs.SetInputConnection(ic.GetOutputPort()) gs.SetDimensionality(2) gs.SetRadiusFactors(1,1,0) # gradient the image imgGradient = vtk.vtkImageGradient() imgGradient.SetInputConnection(gs.GetOutputPort()) imgGradient.SetDimensionality(2) imgMagnitude = vtk.vtkImageMagnitude() imgMagnitude.SetInputConnection(imgGradient.GetOutputPort()) imgMagnitude.Update() # non maximum suppression nonMax = vtk.vtkImageNonMaximumSuppression() nonMax.SetMagnitudeInputData(imgMagnitude.GetOutput()) nonMax.SetVectorInputData(imgGradient.GetOutput()) nonMax.SetDimensionality(2) pad = vtk.vtkImageConstantPad() pad.SetInputConnection(imgGradient.GetOutputPort()) pad.SetOutputNumberOfScalarComponents(3) pad.SetConstant(0) pad.Update() i2sp1 = vtk.vtkImageToStructuredPoints() i2sp1.SetInputConnection(nonMax.GetOutputPort()) i2sp1.SetVectorInputData(pad.GetOutput()) # link edgles imgLink = vtk.vtkLinkEdgels() imgLink.SetInputConnection(i2sp1.GetOutputPort()) imgLink.SetGradientThreshold(2)
def setupPipeline(): #read file global reader reader = vtk.vtkOBJReader() reader.SetFileName(filename) #map 3d model global mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(reader.GetOutputPort()) #set actor global actor actor = vtk.vtkActor() actor.SetMapper(mapper) # Create a rendering window and renderer global ren ren = vtk.vtkRenderer() ren.SetBackground(0, 0, 0) ren.AddActor(actor) global intermediateWindow intermediateWindow = vtk.vtkRenderWindow() intermediateWindow.AddRenderer(ren) #render image global renImage renImage = vtk.vtkRenderLargeImage() renImage.SetInput(ren) renImage.SetMagnification(magnificationFactor) #Canny edge detector inspired by #https://vtk.org/Wiki/VTK/Examples/Cxx/Images/CannyEdgeDetector #to grayscale global lumImage lumImage = vtk.vtkImageLuminance() lumImage.SetInputConnection(renImage.GetOutputPort()) #to float global floatImage floatImage = vtk.vtkImageCast() floatImage.SetOutputScalarTypeToFloat() floatImage.SetInputConnection(lumImage.GetOutputPort()) #gaussian convolution global smoothImage smoothImage = vtk.vtkImageGaussianSmooth() smoothImage.SetInputConnection(floatImage.GetOutputPort()) smoothImage.SetDimensionality(2) smoothImage.SetRadiusFactors(1, 1, 0) #gradient global gradientImage gradientImage = vtk.vtkImageGradient() gradientImage.SetInputConnection(smoothImage.GetOutputPort()) gradientImage.SetDimensionality(2) #gradient magnitude global magnitudeImage magnitudeImage = vtk.vtkImageMagnitude() magnitudeImage.SetInputConnection(gradientImage.GetOutputPort()) #non max suppression global nonmaxSuppr nonmaxSuppr = vtk.vtkImageNonMaximumSuppression() nonmaxSuppr.SetDimensionality(2) #padding global padImage padImage = vtk.vtkImageConstantPad() padImage.SetInputConnection(gradientImage.GetOutputPort()) padImage.SetOutputNumberOfScalarComponents(3) padImage.SetConstant(0) #to structured points global i2sp1 i2sp1 = vtk.vtkImageToStructuredPoints() i2sp1.SetInputConnection(nonmaxSuppr.GetOutputPort()) #link edges global linkImage linkImage = vtk.vtkLinkEdgels() linkImage.SetInputConnection(i2sp1.GetOutputPort()) linkImage.SetGradientThreshold(2) #thresholds links global thresholdEdgels thresholdEdgels = vtk.vtkThreshold() thresholdEdgels.SetInputConnection(linkImage.GetOutputPort()) thresholdEdgels.ThresholdByUpper(10) thresholdEdgels.AllScalarsOff() #filter global gf gf = vtk.vtkGeometryFilter() gf.SetInputConnection(thresholdEdgels.GetOutputPort()) #to structured points global i2sp i2sp = vtk.vtkImageToStructuredPoints() i2sp.SetInputConnection(magnitudeImage.GetOutputPort()) #subpixel global spe spe = vtk.vtkSubPixelPositionEdgels() spe.SetInputConnection(gf.GetOutputPort()) #stripper global strip strip = vtk.vtkStripper() strip.SetInputConnection(spe.GetOutputPort()) global dsm dsm = vtk.vtkPolyDataMapper() dsm.SetInputConnection(strip.GetOutputPort()) dsm.ScalarVisibilityOff() global planeActor planeActor = vtk.vtkActor() planeActor.SetMapper(dsm) planeActor.GetProperty().SetAmbient(1.0) planeActor.GetProperty().SetDiffuse(0.0) global edgeRender edgeRender = vtk.vtkRenderer() edgeRender.AddActor(planeActor) global renderWindow renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(edgeRender) global finalImage finalImage = vtk.vtkRenderLargeImage() finalImage.SetMagnification(magnificationFactor) finalImage.SetInput(edgeRender) global revImage revImage = vtk.vtkImageThreshold() revImage.SetInputConnection(finalImage.GetOutputPort()) revImage.ThresholdByUpper(127) revImage.ReplaceInOn() revImage.ReplaceOutOn() revImage.SetOutValue(255) revImage.SetInValue(0) #write image global imgWriter imgWriter = vtk.vtkPNGWriter() imgWriter.SetInputConnection(revImage.GetOutputPort()) imgWriter.SetFileName("test.png")