def AnisotropicFilter(self, image, num_iterations, diffusion_threshold, diffusion_factor, faces_on=True, edges_on=True, corners_on=True): """Returns a edge-preserving smoothed version of image""" image.SetReleaseDataFlag(1) _filter = vtk.vtkImageAnisotropicDiffusion3D() _filter.SetNumberOfIterations(int(num_iterations)) _filter.SetDiffusionThreshold(float(diffusion_threshold)) _filter.SetDiffusionFactor(float(diffusion_factor)) _filter.SetFaces(int(faces_on)) _filter.SetEdges(int(edges_on)) _filter.SetCorners(int(corners_on)) # we need this here because there are two paths into this routine if isinstance(image, MVImage.MVImage): real_image = image.GetRealImage() else: real_image = image _filter.SetInput(real_image) _filter.SetProgressText("Smoothing image...") _filter.AddObserver('ProgressEvent', self.HandleVTKProgressEvent) logging.info("Anisotropic filter applied") _filter.Update() return MVImage.MVImage(_filter.GetOutputPort(), input=image)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkImageAnisotropicDiffusion3D(), 'Processing.', ('vtkImageData',), ('vtkImageData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkImageAnisotropicDiffusion3D(), 'Processing.', ('vtkImageData', ), ('vtkImageData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self): """ Initialization """ ProcessingFilter.ProcessingFilter.__init__(self, (1, 1)) self.vtkfilter = vtk.vtkImageAnisotropicDiffusion3D() self.eventDesc = "Performing edge preserving smoothing (anisotropic diffusion)" self.vtkfilter.AddObserver('ProgressEvent', lib.messenger.send) lib.messenger.connect(self.vtkfilter, "ProgressEvent", self.updateProgress) self.descs = {"Faces": "Faces", "Corners": "Corners", "Edges": "Edges", "CentralDiff": "Central difference", "Gradient": "Gradient to neighbor", "DiffThreshold": "Diffusion threshold:", "DiffFactor": "Diffusion factor:"} self.filterDesc = "Performs anisotropic diffusion inside the neighborhood that fulfills given parameters\nInput: Grayscale image\nOutput: Grayscale image"
#!/usr/bin/env python import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # Diffuses to 26 neighbors if difference is below threshold. # Image pipeline reader = vtk.vtkImageReader() reader.SetDataByteOrderToLittleEndian() reader.SetDataExtent(0, 63, 0, 63, 1, 93) reader.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") reader.SetDataMask(0x7fff) reader.SetDataSpacing(1, 1, 2) diffusion = vtk.vtkImageAnisotropicDiffusion3D() diffusion.SetInputConnection(reader.GetOutputPort()) diffusion.SetDiffusionFactor(1.0) diffusion.SetDiffusionThreshold(100.0) diffusion.SetNumberOfIterations(5) diffusion.GetExecutive().SetReleaseDataFlag(0, 0) viewer = vtk.vtkImageViewer() #viewer DebugOn viewer.SetInputConnection(diffusion.GetOutputPort()) viewer.SetZSlice(22) viewer.SetColorWindow(3000) viewer.SetColorLevel(1500) #make interface viewer.Render() # --- end of script --
#!/usr/bin/env python import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # Diffuses to 26 neighbors if difference is below threshold. # Image pipeline reader = vtk.vtkImageReader() reader.SetDataByteOrderToLittleEndian() reader.SetDataExtent(0,63,0,63,1,93) reader.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") reader.SetDataMask(0x7fff) reader.SetDataSpacing(1,1,2) diffusion = vtk.vtkImageAnisotropicDiffusion3D() diffusion.SetInputConnection(reader.GetOutputPort()) diffusion.SetDiffusionFactor(1.0) diffusion.SetDiffusionThreshold(100.0) diffusion.SetNumberOfIterations(5) diffusion.GetExecutive().SetReleaseDataFlag(0,0) viewer = vtk.vtkImageViewer() #viewer DebugOn viewer.SetInputConnection(diffusion.GetOutputPort()) viewer.SetZSlice(22) viewer.SetColorWindow(3000) viewer.SetColorLevel(1500) #make interface viewer.Render() # --- end of script --