Exemple #1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkImageConvolve(), 'Processing.',
         ('vtkImageData',), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkImageConvolve(),
                                       'Processing.', ('vtkImageData', ),
                                       ('vtkImageData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemple #3
0
 def ApplyConvolution(self, imagedata, update_progress = None):
     number_filters = len(self.config['convolutionFilters'])
     if number_filters:
         if not(update_progress):
             update_progress = vtk_utils.ShowProgress(number_filters)
         for filter in self.config['convolutionFilters']:
             convolve = vtk.vtkImageConvolve()
             convolve.SetInput(imagedata)
             convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]])
             convolve.AddObserver("ProgressEvent", lambda obj,evt:
                                  update_progress(convolve, "Rendering..."))
             imagedata = convolve.GetOutput()
             #convolve.GetOutput().ReleaseDataFlagOn()
     return imagedata
Exemple #4
0
    def ApplyConvolution(self, imagedata, update_progress = None):
        number_filters = len(self.config['convolutionFilters'])
        if number_filters:
            if not(update_progress):
                update_progress = vtk_utils.ShowProgress(number_filters)
            for filter in self.config['convolutionFilters']:
                convolve = vtk.vtkImageConvolve()
                convolve.SetInputData(imagedata)
                convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]])
                #  convolve.ReleaseDataFlagOn()

                convolve_ref = weakref.ref(convolve)
                
                convolve_ref().AddObserver("ProgressEvent", lambda obj,evt:
                                     update_progress(convolve_ref(), "Rendering..."))
                convolve.Update()
                del imagedata
                imagedata = convolve.GetOutput()
                del convolve
                #convolve.GetOutput().ReleaseDataFlagOn()
        return imagedata
Exemple #5
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

# Show the constant kernel.  Smooth an impulse function.
s1 = vtk.vtkImageCanvasSource2D()
s1.SetScalarTypeToFloat()
s1.SetExtent(0, 255, 0, 255, 0, 0)
s1.SetDrawColor(0)
s1.FillBox(0, 255, 0, 255)
s1.SetDrawColor(1.0)
s1.FillBox(75, 175, 75, 175)
convolve = vtk.vtkImageConvolve()
convolve.SetInputConnection(s1.GetOutputPort())
convolve.SetKernel5x5([
    1, 1, 1, 1, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1
])
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(convolve.GetOutputPort())
viewer.SetColorWindow(18)
viewer.SetColorLevel(9)
viewer.Render()
# --- end of script --
def VTKConvolve(im,numret=0,k=5,clip=1,x=1,y=1,wrap=0,mirror=1,constant=None,
                kernel=None):
      if type(im) == np.ndarray: i = NumToVTKImage(im)
      else: i = im
      d = i.GetDimensions()
      e = i.GetExtent()
      dtest = np.sort(d)
      if sum(dtest[:2]) == 2: onedim=1
      else: onedim = 0
      if (d[0] == 1): oned = 1
      elif (d[1] == 1): oned = 2
      else: oned = 0
      if x and not y: oned = 2
      if y and not x: oned = 1
      if onedim: oned = 1
      if constant is not None:
          ip = vtk.vtkImageConstantPad()
          if d[0] > 1: x0,x1=-k,d[0]+k-1
          else: x0,x1=0,0
          if d[1] > 1: y0,y1=-k,d[1]+k-1
          else: y0,y1=0,0
          ip.SetOutputWholeExtent(x0,x1,y0,y1,0,0)
          ip.SetConstant(constant)
          ip.SetInputData(i)
          i = ip.GetOutput()
          ip.Update()
      elif mirror:
          ip = vtk.vtkImageMirrorPad()
          if d[0] > 1: x0,x1=-k,d[0]+k-1
          else: x0,x1=0,0
          if d[1] > 1: y0,y1=-k,d[1]+k-1
          else: y0,y1=0,0
          ip.SetOutputWholeExtent(x0,x1,y0,y1,0,0)
          ip.SetInputData(i)
          i = ip.GetOutput()
          ip.Update()
      elif wrap:
          ip = vtk.vtkImageWrapPad()
          if d[0] > 1: x0,x1=-k,d[0]+k-1
          else: x0,x1=0,0
          if d[1] > 1: y0,y1=-k,d[1]+k-1
          else: y0,y1=0,0
          ip.SetOutputWholeExtent(x0,x1,y0,y1,0,0)
          ip.SetInputData(i)
          i = ip.GetOutput()
          ip.Update()
      c = vtk.vtkImageConvolve()
      if kernel is None:
          if k == 3: k1 = np.asarray([0.25,0.5,0.25])
          elif k == 5: k1 = np.asarray([0.0625,0.25,0.375,0.25,0.0625])
          if onedim: ke = np.ones((k,k),np.float64) * k1
          elif not oned: ke = k1[::,np.newaxis]*k1[np.newaxis,::]
          elif oned == 1: ke = np.zeros((k,k),np.float64); ke[::,2] = k1
          elif oned == 2: ke = np.zeros((k,k),np.float64); ke[2] = k1
          ke = np.ravel(ke)
          ke = ke / np.sum(ke)
          if onedim: ke = len(k1)*ke
      else:
          k = kernel.shape[0]
          ke = np.ravel(kernel)
      if k == 3: c.SetKernel3x3(ke)
      if k == 5: c.SetKernel5x5(ke)
      if k == 7: c.SetKernel7x7(ke)
      c.SetInputData(i)
      o = c.GetOutput()
      c.Update()
      if clip:
         ic = vtk.vtkImageClip()
         notx = -(not x) * 0
         noty = -(not y) * 0
         ic.SetOutputWholeExtent(notx,d[0]-1+notx,noty,d[1]-1+noty,0,0)
         ic.SetInputData(o)
         ic.ClipDataOn()
         o = ic.GetOutput()
         ic.Update()
      if numret: return VTKImageToNum(o)
      else: return o
Exemple #7
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Show the constant kernel.  Smooth an impulse function.
s1 = vtk.vtkImageCanvasSource2D()
s1.SetScalarTypeToFloat()
s1.SetExtent(0,255,0,255,0,0)
s1.SetDrawColor(0)
s1.FillBox(0,255,0,255)
s1.SetDrawColor(1.0)
s1.FillBox(75,175,75,175)
convolve = vtk.vtkImageConvolve()
convolve.SetInputConnection(s1.GetOutputPort())
convolve.SetKernel5x5([1,1,1,1,1,5,4,3,2,1,5,4,3,2,1,5,4,3,2,1,1,1,1,1,1])
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(convolve.GetOutputPort())
viewer.SetColorWindow(18)
viewer.SetColorLevel(9)
viewer.Render()
# --- end of script --