def computeImageHessian(
        image=None,
        image_filename=None,
        verbose=0):

    myVTK.myPrint(verbose, "*** computeImageHessian ***")

    image = myVTK.initImage(image, image_filename, verbose-1)

    image_dimensionality = myVTK.computeImageDimensionality(
        image=image,
        verbose=verbose-1)

    image_gradient = vtk.vtkImageGradient()
    if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
        image_gradient.SetInputData(image)
    else:
        image_gradient.SetInput(image)
    image_gradient.SetDimensionality(image_dimensionality)
    image_gradient.Update()
    image_w_gradient = image_gradient.GetOutput()

    image_append_components = vtk.vtkImageAppendComponents()
    for k_dim in xrange(image_dimensionality):
        image_extract_components = vtk.vtkImageExtractComponents()
        if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
            image_extract_components.SetInputData(image_w_gradient)
        else:
            image_extract_components.SetInput(image_w_gradient)
        image_extract_components.SetComponents(k_dim)
        image_extract_components.Update()
        image_w_gradient_component = image_extract_components.GetOutput()

        image_gradient = vtk.vtkImageGradient()
        if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
            image_gradient.SetInputData(image_w_gradient_component)
        else:
            image_gradient.SetInput(image_w_gradient_component)
        image_gradient.SetDimensionality(image_dimensionality)
        image_gradient.Update()
        image_w_hessian_component = image_gradient.GetOutput()
        if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
            image_append_components.AddInputData(image_w_hessian_component)
        else:
            image_append_components.AddInput(image_w_hessian_component)

    image_append_components.Update()
    image_w_hessian = image_append_components.GetOutput()

    name = image.GetPointData().GetScalars().GetName()
    image.GetPointData().AddArray(image_w_gradient.GetPointData().GetArray(name+"Gradient"))
    image.GetPointData().AddArray(image_w_hessian.GetPointData().GetArray(name+"GradientGradient"))
    image.GetPointData().SetActiveScalars(name+"GradientGradient")

    return image
def computeImageGradient(
        image=None,
        image_filename=None,
        image_dimensionality=None,
        verbose=0):

    myVTK.myPrint(verbose, "*** computeImageGradient ***")

    image = myVTK.initImage(image, image_filename, verbose-1)

    if (image_dimensionality is None):
        image_dimensionality = myVTK.computeImageDimensionality(
            image=image,
            verbose=verbose-1)

    image_gradient = vtk.vtkImageGradient()
    if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
        image_gradient.SetInputData(image)
    else:
        image_gradient.SetInput(image)
    image_gradient.SetDimensionality(image_dimensionality)
    image_gradient.Update()
    image_w_grad = image_gradient.GetOutput()

    return image_w_grad
Ejemplo n.º 3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self,
         module_manager,
         vtk.vtkImageGradient(),
         "Processing.",
         ("vtkImageData",),
         ("vtkImageData",),
         replaceDoc=True,
         inputFunctions=None,
         outputFunctions=None,
     )
Ejemplo n.º 4
0
def addImageGradient(
        image,
        image_dimensionality=None,
        verbose=0):

    mypy.my_print(verbose, "*** addImageGradient ***")

    if (image_dimensionality is None):
        image_dimensionality = myvtk.getImageDimensionality(
            image=image,
            verbose=verbose-1)

    image_gradient = vtk.vtkImageGradient()
    if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
        image_gradient.SetInputData(image)
    else:
        image_gradient.SetInput(image)
    image_gradient.SetDimensionality(image_dimensionality)
    image_gradient.Update()
    image_w_grad = image_gradient.GetOutput()

    name = image.GetPointData().GetScalars().GetName()
    image.GetPointData().AddArray(image_w_gradient.GetPointData().GetArray(name+"Gradient"))
    image.GetPointData().SetActiveScalars(name+"Gradient")
Ejemplo n.º 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 test the euclidean to polar by coverting 2D vectors
# from a gradient into polar, which is converted into HSV, and then to RGB.
# Image pipeline
gauss = vtk.vtkImageGaussianSource()
gauss.SetWholeExtent(0,255,0,255,0,44)
gauss.SetCenter(127,127,22)
gauss.SetStandardDeviation(50.0)
gauss.SetMaximum(10000.0)
gradient = vtk.vtkImageGradient()
gradient.SetInputConnection(gauss.GetOutputPort())
gradient.SetDimensionality(2)
polar = vtk.vtkImageEuclideanToPolar()
polar.SetInputConnection(gradient.GetOutputPort())
polar.SetThetaMaximum(255)
viewer = vtk.vtkImageViewer()
#viewer DebugOn
viewer.SetInputConnection(polar.GetOutputPort())
viewer.SetZSlice(22)
viewer.SetColorWindow(255)
viewer.SetColorLevel(127.5)
#make interface
viewer.Render()
# --- end of script --
 vtkImageMask.SetInValue(1.0)
 vtkImageMask.SetOutputScalarTypeToDouble()
 try:
   #default look for a user defined image mask
   maskFileName = "%s/SNRuncert.%04d.vtk" %  (
                 FileNameTemplate[:FileNameTemplate.rfind("/")],timeID)
   vtkMaskReader = vtk.vtkDataSetReader() 
   vtkMaskReader.SetFileName( maskFileName ) 
   vtkMaskReader.Update() 
   # set threshold
   vtkImageMask.ThresholdByLower( 100.0)
   vtkImageMask.SetInput(vtkMaskReader.GetOutput())
 except: # if nothing available threshold the phase image
   # take gradient
   vtkPhaseData = ConvertNumpyVTKImage( phase_curr )
   vtkGradientImage = vtk.vtkImageGradient() 
   vtkGradientImage.SetInput(vtkPhaseData) 
   vtkGradientImage.Update() 
   
   # take magnitude of gradient
   vtkImageNorm = vtk.vtkImageMagnitude() 
   vtkImageNorm.SetInput(vtkGradientImage.GetOutput())
   vtkImageNorm.Update() 
   # set threshold
   vtkImageMask.ThresholdByLower( 100.0* tmap_factor * 2.0*numpy.pi/4095.)
   vtkImageMask.SetInput(vtkImageNorm.GetOutput())
 vtkImageMask.Update( )
 # check output
 vtkWriter = vtk.vtkXMLImageDataWriter()
 vtkWriter.SetFileName("threshold.%04d.vti" % timeID )
 vtkWriter.SetInput( vtkImageMask.GetOutput() )