コード例 #1
0
ファイル: vmtkimagevoipainter.py プロジェクト: zymale/vmtk
    def PaintVOI(self):

        wholeExtent = self.Image.GetExtent()[:]
        origin = self.Image.GetOrigin()
        spacing = self.Image.GetSpacing()

        paintedVOI = [0, 0, 0, 0, 0, 0]
        paintedVOI[0] = max(
            wholeExtent[0],
            int(math.ceil((self.BoxBounds[0] - origin[0]) / spacing[0])))
        paintedVOI[1] = min(
            wholeExtent[1],
            int(math.floor((self.BoxBounds[1] - origin[0]) / spacing[0])))
        paintedVOI[2] = max(
            wholeExtent[2],
            int(math.ceil((self.BoxBounds[2] - origin[1]) / spacing[1])))
        paintedVOI[3] = min(
            wholeExtent[3],
            int(math.floor((self.BoxBounds[3] - origin[1]) / spacing[1])))
        paintedVOI[4] = max(
            wholeExtent[4],
            int(math.ceil((self.BoxBounds[4] - origin[2]) / spacing[2])))
        paintedVOI[5] = min(
            wholeExtent[5],
            int(math.floor((self.BoxBounds[5] - origin[2]) / spacing[2])))

        # extent trick. TODO: fix vtkvmtkImageBoxPainter
        paintedVOI[0] -= wholeExtent[0]
        paintedVOI[1] -= wholeExtent[0]
        paintedVOI[2] -= wholeExtent[2]
        paintedVOI[3] -= wholeExtent[2]
        paintedVOI[4] -= wholeExtent[4]
        paintedVOI[5] -= wholeExtent[4]

        translate = vtk.vtkImageTranslateExtent()
        translate.SetInputData(self.Image)
        translate.SetTranslation(-wholeExtent[0], -wholeExtent[2],
                                 -wholeExtent[4])
        translate.Update()

        imageBoxPainter = vtkvmtk.vtkvmtkImageBoxPainter()
        imageBoxPainter.SetInputConnection(translate.GetOutputPort())
        imageBoxPainter.SetBoxExtent(paintedVOI)
        imageBoxPainter.SetBoxDefinitionToUseExtent()
        imageBoxPainter.SetPaintValue(self.PaintValue)
        imageBoxPainter.Update()

        translate = vtk.vtkImageTranslateExtent()
        translate.SetInputConnection(imageBoxPainter.GetOutputPort())
        translate.SetTranslation(wholeExtent[0], wholeExtent[2],
                                 wholeExtent[4])
        translate.Update()

        self.Image.ShallowCopy(translate.GetOutput())
コード例 #2
0
ファイル: vmtkmarchingcubes.py プロジェクト: Clemson-MSE/vmtk
    def Execute(self):

        if self.Image == None:
            self.PrintError('Error: No Image.')

        extent = self.Image.GetExtent()
        translateExtent = vtk.vtkImageTranslateExtent()
        translateExtent.SetInputData(self.Image)
        translateExtent.SetTranslation(-extent[0],-extent[2],-extent[4])
        translateExtent.Update()

        if (self.ArrayName != ''):
            translateExtent.GetOutput().GetPointData().SetActiveScalars(self.ArrayName)

        marchingCubes = vtk.vtkMarchingCubes()
        marchingCubes.SetInputConnection(translateExtent.GetOutputPort())
        marchingCubes.SetValue(0,self.Level)
        marchingCubes.Update()

        self.Surface = marchingCubes.GetOutput()

        if self.Connectivity == 1:
            connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
            connectivityFilter.SetInputData(self.Surface)
            connectivityFilter.SetExtractionModeToLargestRegion()
            connectivityFilter.Update()
            self.Surface = connectivityFilter.GetOutput()
コード例 #3
0
def VTKImageShift(x,u,v,numret=False,interp=True,wrap=False,mirror=False,
   constant=None,cubic=False):
   if type(x) == type(np.arange(2)): i = NumToVTKImage(x)
   else: i = x
   if 0 and int(u) == u and int(v) == v:
      s = vtk.vtkImageTranslateExtent()
      s.SetInput(i)
      s.SetTranslation(u,v,0)
      o = s.GetOutput()
      s.Update()
   else:
      s = vtk.vtkImageReslice()
      s.AutoCropOutputOn()
      if wrap: s.WrapOn()
      else: s.WrapOff()
      if mirror or constant != None: s.MirrorOn()
      else: s.MirrorOff()
      if interp:
        s.InterpolateOn()
        if cubic:
          s.SetInterpolationModeToCubic()
        else:
          s.SetInterpolationModeToLinear()
      else: s.InterpolateOff()
      s.OptimizationOn()
      s.SetOutputOrigin(u,v,0)
      s.SetInputData(i)
      o=s.GetOutput()
      s.Update()
   if numret: return VTKImageToNum(o)
   else: return o
コード例 #4
0
ファイル: vmtkmarchingcubes.py プロジェクト: 151706061/vmtk
    def Execute(self):

        if self.Image == None:
            self.PrintError('Error: No Image.')

        extent = self.Image.GetExtent()
        translateExtent = vtk.vtkImageTranslateExtent()
        translateExtent.SetInputData(self.Image)
        translateExtent.SetTranslation(-extent[0],-extent[2],-extent[4])
        translateExtent.Update()

        if (self.ArrayName != ''):
            translateExtent.GetOutput().GetPointData().SetActiveScalars(self.ArrayName)

        marchingCubes = vtk.vtkMarchingCubes()
        marchingCubes.SetInputConnection(translateExtent.GetOutputPort())
        marchingCubes.SetValue(0,self.Level)
        marchingCubes.Update()

        self.Surface = marchingCubes.GetOutput()

        if self.Connectivity == 1:
            connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
            connectivityFilter.SetInputData(self.Surface)
            connectivityFilter.SetExtractionModeToLargestRegion()
            connectivityFilter.Update()
            self.Surface = connectivityFilter.GetOutput()
コード例 #5
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkImageTranslateExtent(),
                                       'Processing.', ('vtkImageData', ),
                                       ('vtkImageData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
コード例 #6
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self,
         module_manager,
         vtk.vtkImageTranslateExtent(),
         "Processing.",
         ("vtkImageData",),
         ("vtkImageData",),
         replaceDoc=True,
         inputFunctions=None,
         outputFunctions=None,
     )
コード例 #7
0
ファイル: vmtkimagevoipainter.py プロジェクト: vmtk/vmtk
    def PaintVOI(self):

        wholeExtent = self.Image.GetExtent()[:]
        origin = self.Image.GetOrigin()
        spacing = self.Image.GetSpacing()

        paintedVOI = [0,0,0,0,0,0]
        paintedVOI[0] = max(wholeExtent[0],int(math.ceil((self.BoxBounds[0]-origin[0])/spacing[0])))
        paintedVOI[1] = min(wholeExtent[1],int(math.floor((self.BoxBounds[1]-origin[0])/spacing[0])))
        paintedVOI[2] = max(wholeExtent[2],int(math.ceil((self.BoxBounds[2]-origin[1])/spacing[1])))
        paintedVOI[3] = min(wholeExtent[3],int(math.floor((self.BoxBounds[3]-origin[1])/spacing[1])))
        paintedVOI[4] = max(wholeExtent[4],int(math.ceil((self.BoxBounds[4]-origin[2])/spacing[2])))
        paintedVOI[5] = min(wholeExtent[5],int(math.floor((self.BoxBounds[5]-origin[2])/spacing[2])))

        # extent trick. TODO: fix vtkvmtkImageBoxPainter
        paintedVOI[0] -= wholeExtent[0]
        paintedVOI[1] -= wholeExtent[0]
        paintedVOI[2] -= wholeExtent[2]
        paintedVOI[3] -= wholeExtent[2]
        paintedVOI[4] -= wholeExtent[4]
        paintedVOI[5] -= wholeExtent[4]

        translate = vtk.vtkImageTranslateExtent()
        translate.SetInputData(self.Image)
        translate.SetTranslation(-wholeExtent[0],-wholeExtent[2],-wholeExtent[4])
        translate.Update()

        imageBoxPainter = vtkvmtk.vtkvmtkImageBoxPainter()
        imageBoxPainter.SetInputConnection(translate.GetOutputPort())
        imageBoxPainter.SetBoxExtent(paintedVOI)
        imageBoxPainter.SetBoxDefinitionToUseExtent()
        imageBoxPainter.SetPaintValue(self.PaintValue)
        imageBoxPainter.Update()

        translate = vtk.vtkImageTranslateExtent()
        translate.SetInputConnection(imageBoxPainter.GetOutputPort())
        translate.SetTranslation(wholeExtent[0],wholeExtent[2],wholeExtent[4])
        translate.Update()

        self.Image.ShallowCopy(translate.GetOutput())
コード例 #8
0
ファイル: TestStencilWithImage.py プロジェクト: 0004c/VTK
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# A script to test the stencil filter by using one image
# to stencil another
# Image pipeline
reader1 = vtk.vtkBMPReader()
reader1.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp")
reader2 = vtk.vtkPNMReader()
reader2.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/B.pgm")
translate = vtk.vtkImageTranslateExtent()
translate.SetInputConnection(reader2.GetOutputPort())
translate.SetTranslation(60,60,0)
imageToStencil = vtk.vtkImageToImageStencil()
imageToStencil.SetInputConnection(translate.GetOutputPort())
imageToStencil.ThresholdBetween(0,127)
# silly stuff to increase coverage
imageToStencil.SetUpperThreshold(imageToStencil.GetUpperThreshold())
imageToStencil.SetLowerThreshold(imageToStencil.GetLowerThreshold())
stencil = vtk.vtkImageStencil()
stencil.SetInputConnection(reader1.GetOutputPort())
stencil.SetBackgroundValue(0)
stencil.ReverseStencilOn()
stencil.SetStencilConnection(imageToStencil.GetOutputPort())
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(stencil.GetOutputPort())
viewer.SetColorWindow(255.0)
viewer.SetColorLevel(127.5)
コード例 #9
0
ファイル: TestBlendStencil.py プロジェクト: ciwei100000/vtk7
# do alpha-blending of two images, but also clip with stencil
reader1 = vtk.vtkBMPReader()
reader1.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")

reader2 = vtk.vtkPNMReader()
reader2.SetFileName(VTK_DATA_ROOT + "/Data/B.pgm")

table = vtk.vtkLookupTable()
table.SetTableRange(0, 127)
table.SetValueRange(0.0, 1.0)
table.SetSaturationRange(0.0, 0.0)
table.SetHueRange(0.0, 0.0)
table.SetAlphaRange(0.9, 0.0)
table.Build()

translate = vtk.vtkImageTranslateExtent()
translate.SetInputConnection(reader2.GetOutputPort())
translate.SetTranslation(60, 60, 0)

sphere = vtk.vtkSphere()
sphere.SetCenter(121, 131, 0)
sphere.SetRadius(70)

functionToStencil = vtk.vtkImplicitFunctionToImageStencil()
functionToStencil.SetInput(sphere)

blend = vtk.vtkImageBlend()
blend.SetInputConnection(reader1.GetOutputPort())
blend.AddInputConnection(translate.GetOutputPort())

# excercise the ReplaceNthInputConnection method
コード例 #10
0
ファイル: ExtractSubset.py プロジェクト: scijava/bioimagexd
    def execute(self, inputs, update=0, last=0):
        """
		Execute the filter with given inputs and return the output
		"""
        if not lib.ProcessingFilter.ProcessingFilter.execute(self, inputs):
            return None

        maxx, maxy, maxz = self.dataUnit.getDimensions()
        minx = 0
        miny = 0
        minz = 0
        if self.parameters["UseROI"]:
            minx, maxx = 99999, 0
            miny, maxy = 99999, 0
            roi = self.parameters["ROI"][1]
            pts = roi.getCoveredPoints()
            for (x, y) in pts:
                if minx > x:
                    minx = x
                if x > maxx:
                    maxx = x
                if miny > y:
                    miny = y
                if y > maxy:
                    maxy = y

        minz = self.parameters["FirstSlice"]
        maxz = self.parameters["LastSlice"]
        minz -= 1
        maxz -= 1
        maxx -= 1
        maxy -= 1
        scripting.wantWholeDataset = 1
        imagedata = self.getInput(1)
        imagedata.SetUpdateExtent(imagedata.GetWholeExtent())
        imagedata.Update()

        # Mask original image
        if self.parameters["UseROI"]:
            mask = lib.ImageOperations.getMaskFromPoints(
                pts, maxx + 1, maxy + 1, maxz + 1)
            maskFilter = vtk.vtkImageMask()
            maskFilter.SetImageInput(imagedata)
            maskFilter.SetMaskInput(mask)
            imagedata = maskFilter.GetOutput()
            imagedata.Update()

        # Extract VOI of original data
        self.vtkfilter.SetInput(imagedata)
        self.vtkfilter.SetVOI(minx, maxx, miny, maxy, minz, maxz)
        data = self.vtkfilter.GetOutput()
        translate = vtk.vtkImageTranslateExtent()
        translate.SetInput(data)
        #print "input data=",data
        translation = [0, 0, 0]
        if minz > 0:
            translation[2] = -minz
        if minx > 0:
            translation[0] = -minx
        if miny > 0:
            translation[1] = -miny
        newTranslation = translation[:]
        #if self.translation:
        #	dx = self.translation[0]-minx
        #	dy = self.translation[1]-miny
        #	dz = self.translation[2]-minz
        #	newTranslation = [dx,dy,dz]
        self.translation = newTranslation

        #lib.messenger.send(None, bxdevents.TRANSLATE_DATA, tuple(self.translation))
        if translation != [0, 0, 0]:
            translate.SetTranslation(tuple(translation))
            #translate.SetOutputOrigin(0,0,0)
            data = translate.GetOutput()
            data.Update()

        reslice = vtk.vtkImageChangeInformation()
        reslice.SetOutputOrigin(0, 0, 0)
        reslice.SetInput(data)
        data = reslice.GetOutput()
        print "Returning data", data
        return data
	def execute(self, inputs, update = 0, last = 0):
		"""
		Execute the filter with given inputs and return the output
		"""            
		if not lib.ProcessingFilter.ProcessingFilter.execute(self, inputs):
			return None

		maxx, maxy, maxz = self.dataUnit.getDimensions()
		minx = 0
		miny = 0
		minz = 0
		if self.parameters["UseROI"]:
			minx, maxx = 99999, 0
			miny, maxy = 99999, 0            
			roi = self.parameters["ROI"][1]
			pts = roi.getCoveredPoints()
			for (x, y) in pts:
				if minx > x:
					minx = x
				if x > maxx:
					maxx = x
				if miny > y:
					miny = y
				if y > maxy:
					maxy = y
  
		minz = self.parameters["FirstSlice"]
		maxz = self.parameters["LastSlice"]
		minz -= 1
		maxz -= 1
		maxx -= 1
		maxy -= 1
		scripting.wantWholeDataset=1
		imagedata = self.getInput(1)
		imagedata.SetUpdateExtent(imagedata.GetWholeExtent())
		imagedata.Update()

		# Mask original image
		if self.parameters["UseROI"]:
			mask = lib.ImageOperations.getMaskFromPoints(pts, maxx+1, maxy+1, maxz+1)
			maskFilter = vtk.vtkImageMask()
			maskFilter.SetImageInput(imagedata)
			maskFilter.SetMaskInput(mask)
			imagedata = maskFilter.GetOutput()
			imagedata.Update()
		
		# Extract VOI of original data
		self.vtkfilter.SetInput(imagedata)
		self.vtkfilter.SetVOI(minx, maxx, miny, maxy, minz, maxz)
		data = self.vtkfilter.GetOutput()
		translate = vtk.vtkImageTranslateExtent()
		translate.SetInput(data)
		#print "input data=",data
		translation = [0,0,0]
		if minz > 0:
			translation[2] = -minz
		if minx > 0:
			translation[0] = -minx
		if miny > 0:
			translation[1] = -miny
		newTranslation = translation[:]
		#if self.translation:
		#	dx = self.translation[0]-minx
		#	dy = self.translation[1]-miny
		#	dz = self.translation[2]-minz
		#	newTranslation = [dx,dy,dz]
		self.translation = newTranslation
		
		#lib.messenger.send(None, bxdevents.TRANSLATE_DATA, tuple(self.translation))
		if translation != [0,0,0]:
			translate.SetTranslation(tuple(translation))
			#translate.SetOutputOrigin(0,0,0)
			data = translate.GetOutput()
			data.Update()
			
		reslice = vtk.vtkImageChangeInformation()
		reslice.SetOutputOrigin(0,0,0)
		reslice.SetInput(data)
		data = reslice.GetOutput()
		print "Returning data",data
		return  data