Beispiel #1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkImageNormalize(), 'Processing.',
         ('vtkImageData',), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
def getImageMask(inputVtkImageData):
    """
    @type  inputVtkImageData: C{vtkImageData}
    @param inputVtkImageData: Image data to be normalized
    
    @rtype: C{vtkImageData}
    @return: Normalized (0-1) image data
    """
    t = vtk.vtkImageThreshold()
    #t.ThresholdBetween(1,255)
    t.ThresholdByUpper(114)
    t.ReplaceInOn()
    t.SetReplaceIn(0)
    t.ReplaceOutOn()
    t.SetReplaceOut(255)
    t.SetInput(inputVtkImageData)
        
    norm = vtk.vtkImageNormalize()
    norm.SetInput(t.GetOutput())
    #norm.SetInput(inputVtkImageData)
    norm.Update()

    d = vtk.vtkImageDilateErode3D()
    d.SetKernelSize(4,4,4)
    d.SetDilateValue(1)
    d.SetErodeValue(0)
    d.SetInput(norm.GetOutput())
    return d.GetOutput()
Beispiel #3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkImageNormalize(),
                                       'Processing.', ('vtkImageData', ),
                                       ('vtkImageData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Beispiel #4
0
 def normalize(self):
     """Normalize that scalar components for each point."""
     norm = vtk.vtkImageNormalize()
     norm.SetInputData(self.imagedata())
     norm.Update()
     return self._update(norm.GetOutput())
Beispiel #5
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# This script is for testing the normalize filter.
# Image pipeline
cos = vtk.vtkImageSinusoidSource()
cos.SetWholeExtent(0, 225, 0, 225, 0, 20)
cos.SetAmplitude(250)
cos.SetDirection(1, 1, 1)
cos.SetPeriod(20)
cos.ReleaseDataFlagOff()
gradient = vtk.vtkImageGradient()
gradient.SetInputConnection(cos.GetOutputPort())
gradient.SetDimensionality(3)
norm = vtk.vtkImageNormalize()
norm.SetInputConnection(gradient.GetOutputPort())
viewer = vtk.vtkImageViewer()
#viewer DebugOn
viewer.SetInputConnection(norm.GetOutputPort())
viewer.SetZSlice(10)
viewer.SetColorWindow(2.0)
viewer.SetColorLevel(0)
viewer.Render()
# --- end of script --
Beispiel #6
0
def main():
    colors = vtk.vtkNamedColors()
    colors.SetColor("right_bkg", [0.4, 0.5, 0.6, 1.0])
    colors.SetColor("left_bkg", [0.6, 0.5, 0.4, 1.0])

    # Create an image
    source = vtk.vtkImageSinusoidSource()
    source.Update()

    normalizeFilter = vtk.vtkImageNormalize()

    normalizeFilter.SetInputConnection(source.GetOutputPort())
    normalizeFilter.Update()

    inputCastFilter = vtk.vtkImageCast()
    inputCastFilter.SetInputConnection(source.GetOutputPort())
    inputCastFilter.SetOutputScalarTypeToUnsignedChar()
    inputCastFilter.Update()

    normalizeCastFilter = vtk.vtkImageCast()
    normalizeCastFilter.SetInputConnection(normalizeFilter.GetOutputPort())
    normalizeCastFilter.SetOutputScalarTypeToUnsignedChar()
    normalizeCastFilter.Update()

    # Create actors
    inputActor = vtk.vtkImageActor()
    inputActor.GetMapper().SetInputConnection(inputCastFilter.GetOutputPort())

    normalizedActor = vtk.vtkImageActor()
    normalizedActor.GetMapper().SetInputConnection(
        normalizeCastFilter.GetOutputPort())

    # There will be one render window
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetSize(600, 300)

    # And one interactor
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    # Define viewport ranges
    # (xmin, ymin, xmax, ymax)
    leftViewport = [0.0, 0.0, 0.5, 1.0]
    rightViewport = [0.5, 0.0, 1.0, 1.0]

    # Setup both renderers
    leftRenderer = vtk.vtkRenderer()
    renderWindow.AddRenderer(leftRenderer)
    leftRenderer.SetViewport(leftViewport)
    leftRenderer.SetBackground(colors.GetColor3d("left_bkg"))

    rightRenderer = vtk.vtkRenderer()
    renderWindow.AddRenderer(rightRenderer)
    rightRenderer.SetViewport(rightViewport)
    rightRenderer.SetBackground(colors.GetColor3d("right_bkg"))

    leftRenderer.AddActor(inputActor)
    rightRenderer.AddActor(normalizedActor)

    leftRenderer.ResetCamera()

    rightRenderer.ResetCamera()

    renderWindow.Render()
    interactor.Start()
Beispiel #7
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

# This script is for testing the normalize filter.
# Image pipeline
cos = vtk.vtkImageSinusoidSource()
cos.SetWholeExtent(0, 225, 0, 225, 0, 20)
cos.SetAmplitude(250)
cos.SetDirection(1, 1, 1)
cos.SetPeriod(20)
cos.ReleaseDataFlagOff()
gradient = vtk.vtkImageGradient()
gradient.SetInputConnection(cos.GetOutputPort())
gradient.SetDimensionality(3)
norm = vtk.vtkImageNormalize()
norm.SetInputConnection(gradient.GetOutputPort())
viewer = vtk.vtkImageViewer()
# viewer DebugOn
viewer.SetInputConnection(norm.GetOutputPort())
viewer.SetZSlice(10)
viewer.SetColorWindow(2.0)
viewer.SetColorLevel(0)
viewer.Render()
# --- end of script --