Exemplo n.º 1
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if not self.InitializationImage:
            self.InitializationImage = self.Image

        if not self.FeatureImage:
            if self.LevelSetsType in ["geodesic", "curves"]:
                imageFeatures = vmtkscripts.vmtkImageFeatures()
                imageFeatures.Image = self.Image
                imageFeatures.FeatureImageType = self.FeatureImageType
                imageFeatures.SigmoidRemapping = self.SigmoidRemapping
                imageFeatures.DerivativeSigma = self.FeatureDerivativeSigma
                imageFeatures.UpwindFactor = self.UpwindFactor
                imageFeatures.FWHMRadius = self.FWHMRadius
                imageFeatures.FWHMBackgroundValue = self.FWHMBackgroundValue
                imageFeatures.Execute()
                self.FeatureImage = imageFeatures.FeatureImage
            elif self.LevelSetsType in ["threshold", "laplacian"]:
                self.FeatureImage = self.Image
            else:
                self.PrintError('Unsupported LevelSetsType')

        if self.NumberOfIterations != 0:
            self.LevelSetsInput = self.InitialLevelSets
            self.LevelSetEvolution()
            self.MergeLevelSet()
            return

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkscripts.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)

        self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
        self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
        #self.ImageSeeder.Image = self.Image
        self.ImageSeeder.Image = self.InitializationImage
        self.ImageSeeder.Display = 0
        self.ImageSeeder.Execute()
        ##self.ImageSeeder.Display = 1
        self.ImageSeeder.BuildView()

        self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
        self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer

        if self.LevelSets != None:
            self.DisplayLevelSetSurface(self.LevelSets, 0.0)

        self.vmtkImageInitialization = vmtkscripts.vmtkImageInitialization()
        #self.vmtkImageInitialization.Image = self.Image
        self.vmtkImageInitialization.Image = self.InitializationImage
        self.vmtkImageInitialization.vmtkRenderer = self.vmtkRenderer
        self.vmtkImageInitialization.ImageSeeder = self.ImageSeeder
        self.vmtkImageInitialization.SurfaceViewer = self.SurfaceViewer
        self.vmtkImageInitialization.NegateImage = self.NegateForInitialization
        self.vmtkImageInitialization.OwnRenderer = 0

        endSegmentation = 0
        while (endSegmentation == 0):

            if self.InitialLevelSets == None:
                self.vmtkImageInitialization.Execute()
                self.LevelSetsInput = self.vmtkImageInitialization.InitialLevelSets
                #                self.IsoSurfaceValue = self.vmtkImageInitialization.IsoSurfaceValue
                self.vmtkImageInitialization.InitialLevelSets = None
                #                self.vmtkImageInitialization.IsosurfaceValue = 0.0
                self.IsoSurfaceValue = 0.0
            else:
                self.LevelSetsInput = self.InitialLevelSets
                self.InitialLevelSets = None
                self.DisplayLevelSetSurface(self.LevelSetsInput,
                                            self.IsoSurfaceValue)

            endEvolution = False
            while not endEvolution:

                queryString = 'Please input parameters (type return to accept current values, \'e\' to end, \'q\' to quit):\nNumberOfIterations(' + str(
                    self.NumberOfIterations) + ') [PropagationScaling(' + str(
                        self.PropagationScaling) + ') CurvatureScaling(' + str(
                            self.CurvatureScaling
                        ) + ') AdvectionScaling(' + str(
                            self.AdvectionScaling) + ')]: '
                inputString = self.InputText(queryString,
                                             self.EvolutionParametersValidator)

                if inputString == 'q':
                    return
                elif inputString == 'e':
                    endEvolution = True
                elif inputString != '':
                    splitInputString = inputString.strip().split(' ')
                    if len(splitInputString) == 1:
                        self.NumberOfIterations = int(splitInputString[0])
                    elif len(splitInputString) == 4:
                        self.NumberOfIterations = int(splitInputString[0])
                        self.PropagationScaling = float(splitInputString[1])
                        self.CurvatureScaling = float(splitInputString[2])
                        self.AdvectionScaling = float(splitInputString[3])
                    else:
                        self.PrintLog('Wrong number of parameters.')
                        continue

                if endEvolution:
                    break

                self.LevelSetEvolution()
                self.DisplayLevelSetSurface(self.LevelSetsOutput)

                queryString = 'Accept result? (y/n): '
                inputString = self.InputText(queryString, self.YesNoValidator)
                if inputString == 'y':
                    endEvolution = True
                elif inputString == 'n':
                    endEvolution = False

            queryString = 'Merge branch? (y/n): '
            inputString = self.InputText(queryString, self.YesNoValidator)
            if inputString == 'y':
                self.MergeLevelSet()
            elif inputString == 'n':
                pass

            if self.LevelSets != None:
                self.DisplayLevelSetSurface(self.LevelSets)

            queryString = 'Segment another branch? (y/n): '
            inputString = self.InputText(queryString, self.YesNoValidator)
            if inputString == 'y':
                endSegmentation = False
            elif inputString == 'n':
                endSegmentation = True
        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
Exemplo n.º 2
0
    def Execute(self):
        print("Compute VC orientation")
        self.ctrliner = vmtkscripts.vmtkCenterlines()
        self.ctrliner.Surface = self.Surface
        self.ctrliner.Execute()
        self.Centerlines = self.ctrliner.Centerlines
        cc = self.Centerlines

        ptCoord = []

        for c in xrange(cc.GetNumberOfPoints()):
            ptCoord.append(cc.GetPoints().GetPoint(c))

        ptCoord = np.array(ptCoord)
        datamean = ptCoord.mean(axis=0)
        uu, dd, vv = np.linalg.svd(ptCoord - datamean)
        # vector of the general direction of the VC
        # print(vv[0], datamean, datamean+10*vv[0])
        VCvect = vv[0]

        if self.ComputeCenterlines:
            # print(self.Surface)
            self.ctrliner = vmtkscripts.vmtkCenterlines()
            self.ctrliner.Surface = self.Surface
            # self.ctrliner.SeedSelector = 'openprofiles'
            self.ctrliner.Execute()
            self.Centerlines = self.ctrliner.Centerlines
            # self.Surface = self.Centerlines
        else:
            self.Centerlines = self.Surface

        # if self.Centerlines == None:
        #     self.PrintError('DUMBASS')

        self.vmtkReader = vmtkscripts.vmtkSurfaceReader()

        self.vmtkRenderer = vmtkscripts.vmtkRenderer()
        self.vmtkRenderer.Initialize()
        self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()

        # self.Surface = self.Centerlines
        self.SurfaceViewer.Surface = self.Surface
        self.SurfaceViewer.Execute()

        self.myattr = vmtkscripts.vmtkCenterlineAttributes()
        self.myattr.Centerlines = self.Centerlines
        self.myattr.Execute()

        self.mybranchextractor = vmtkscripts.vmtkBranchExtractor()
        self.mybranchextractor.Centerlines = self.myattr.Centerlines
        self.mybranchextractor.RadiusArrayName = self.RadiusArrayName
        self.mybranchextractor.Execute()

        self.ctrl = self.mybranchextractor.Centerlines

        self.mywriter = vmtkscripts.vmtkSurfaceWriter()
        self.mywriter.Surface = self.mybranchextractor.Centerlines
        self.mywriter.OutputFileName = '/home/florian/liverSim/morpho_analysis/test_surf_open_small_ctrlTESTbranc1.vtp'
        self.mywriter.Execute()

        self.mybifref = vmtkscripts.vmtkBifurcationReferenceSystems()
        self.mybifref.Centerlines = self.ctrl
        self.mybifref.RadiusArrayName = self.RadiusArrayName
        self.mybifref.BlankingArrayName = self.BlankingArrayName
        self.mybifref.GroupIdsArrayName = self.GroupIdsArrayName
        self.mybifref.CenterlineIdsArrayName = self.CenterlineIdsArrayName
        self.mybifref.TractIdsArrayName = self.TractIdsArrayName
        self.mybifref.Execute()

        self.myvect = vmtkscripts.vmtkBifurcationVectors()
        self.myvect.Centerlines = self.ctrl
        self.myvect.ReferenceSystems = self.mybifref.ReferenceSystems
        self.myvect.RadiusArrayName = self.RadiusArrayName
        self.myvect.BlankingArrayName = self.BlankingArrayName
        self.myvect.GroupIdsArrayName = self.GroupIdsArrayName
        self.myvect.TractIdsArrayName = self.TractIdsArrayName
        self.myvect.CenterlineIdsArrayName = self.CenterlineIdsArrayName
        self.myvect.ReferenceSystemsNormalArrayName = self.mybifref.ReferenceSystemsNormalArrayName
        self.myvect.ReferenceSystemsUpNormalArrayName = self.mybifref.ReferenceSystemsUpNormalArrayName
        self.myvect.Execute()

        '''TEMP'''
        self.mywriter = vmtkscripts.vmtkSurfaceWriter()
        self.mywriter.Surface = self.myvect.BifurcationVectors
        self.mywriter.OutputFileName = '/home/florian/liverSim/morpho_analysis/test_surf_open_small_bifvect.vtp'
        self.mywriter.Execute()

        self.mywriter.Surface = self.ctrl
        self.mywriter.OutputFileName = '/home/florian/liverSim/morpho_analysis/test_surf_open_small_ctrl.vtp'
        self.mywriter.Execute()
        '''/TEMP'''



        self.numpytator = vmtksurfacetonumpy.vmtkSurfaceToNumpy()
        self.numpytator.Surface = self.myvect.BifurcationVectors
        self.numpytator.Execute()
        vectData = self.numpytator.ArrayDict.values()

        cprint(figlet_format('Results!', font='bubble'))
        print('\n InPlaneBifurcationVectors angle:')
        print(np.degrees(self.angle_between(vectData[0]["InPlaneBifurcationVectors"][1, :],
                                            vectData[0]["InPlaneBifurcationVectors"][2, :])))
        # print('\n OutOfPlaneBifurcationVectors angle:')
        # print(np.degrees(self.angle_between(vectData[0]["OutOfPlaneBifurcationVectors"][1, :],
        #                                     vectData[0]["OutOfPlaneBifurcationVectors"][2, :])))
        print('\n bifurcation angle with the VC:')
        print(np.degrees(self.angle_between(vectData[0]["OutOfPlaneBifurcationVectors"][0, :],
                                            VCvect)))
        '''
        weighted average vector between the vectors pointing from the second 
        to the first reference point on each centerline
        '''
        print('\n global direction of the birfurcation:')
        print(vectData[0]["BifurcationVectors"][0, :])
        '''
        the origin of the bifurcation is defined as the barycenter of the four reference points
         weighted by the surface of the maximum inscribed sphere defined on the reference points. 
         The reason of the weighting is that small branches have less impact on the position of 
         the bifurcation origin
        '''
        print('\n Origin of the bifurcation:')
        print(vectData[1][0])
        pass
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if self.NegateImage:
            scalarRange = self.Image.GetScalarRange()
            negate = vtk.vtkImageMathematics()
            negate.SetInputData(self.Image)
            negate.SetOperationToMultiplyByK()
            negate.SetConstantK(-1.0)
            negate.Update()
            shiftScale = vtk.vtkImageShiftScale()
            shiftScale.SetInputConnection(negate.GetOutputPort())
            shiftScale.SetShift(scalarRange[1] + scalarRange[0])
            shiftScale.SetOutputScalarTypeToFloat()
            shiftScale.Update()
            self.Image = shiftScale.GetOutput()

        if self.Interactive:
            if not self.vmtkRenderer:
                self.vmtkRenderer = vmtkscripts.vmtkRenderer()
                self.vmtkRenderer.Initialize()
                self.OwnRenderer = 1

            self.vmtkRenderer.RegisterScript(self)

            if not self.ImageSeeder:
                self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
                self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
                self.ImageSeeder.Image = self.Image
                self.ImageSeeder.Display = 0
                self.ImageSeeder.Execute()
                ##self.ImageSeeder.Display = 1
                self.ImageSeeder.BuildView()

            if not self.SurfaceViewer:
                self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
                self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer

            initializationMethods = {
                '0': self.CollidingFrontsInitialize,
                '1': self.FastMarchingInitialize,
                '2': self.ThresholdInitialize,
                '3': self.IsosurfaceInitialize,
                '4': self.SeedInitialize
            }

            endInitialization = False
            while not endInitialization:
                queryString = 'Please choose initialization type: \n 0: colliding fronts;\n 1: fast marching;\n 2: threshold;\n 3: isosurface;\n 4: seed\n '
                initializationType = self.InputText(
                    queryString, self.InitializationTypeValidator)
                initializationMethods[initializationType]()
                self.DisplayLevelSetSurface(self.InitialLevelSets)
                queryString = 'Accept initialization? (y/n): '
                inputString = self.InputText(queryString, self.YesNoValidator)
                if inputString == 'y':
                    self.MergeLevelSets()
                    self.DisplayLevelSetSurface(self.MergedInitialLevelSets)
                queryString = 'Initialize another branch? (y/n): '
                inputString = self.InputText(queryString, self.YesNoValidator)
                if inputString == 'y':
                    endInitialization = False
                elif inputString == 'n':
                    endInitialization = True

            self.InitialLevelSets = self.MergedInitialLevelSets
            self.MergedInitialLevelSets = None

        else:
            if self.Method == "collidingfronts":
                self.CollidingFrontsInitialize()
            elif self.Method == "fastmarching":
                self.FastMarchingInitialize()
            elif self.Method == "threshold":
                self.ThresholdInitialize()
            elif self.Method == "isosurface":
                self.IsosurfaceInitialize()
            elif self.Method == "seeds":
                self.SeedInitialize()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
Exemplo n.º 4
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if not self.InitializationImage:
            self.InitializationImage = self.Image

        if not self.FeatureImage:
            if self.LevelSetsType in ["geodesic", "curves"]:
                imageFeatures = vmtkscripts.vmtkImageFeatures()
                imageFeatures.Image = self.Image
                imageFeatures.FeatureImageType = self.FeatureImageType
                imageFeatures.SigmoidRemapping = self.SigmoidRemapping
                imageFeatures.DerivativeSigma = self.FeatureDerivativeSigma
                imageFeatures.UpwindFactor = self.UpwindFactor
                imageFeatures.FWHMRadius = self.FWHMRadius
                imageFeatures.FWHMBackgroundValue = self.FWHMBackgroundValue
                imageFeatures.Execute()
                self.FeatureImage = imageFeatures.FeatureImage
            elif self.LevelSetsType in ["threshold", "laplacian"]:
                self.FeatureImage = self.Image
            else:
                self.PrintError('Unsupported LevelSetsType')

        if self.NumberOfIterations != 0:
            self.LevelSetsInput = self.InitialLevelSets
            self.LevelSetEvolution()
            self.MergeLevelSet()
            return

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkscripts.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1
 
        self.vmtkRenderer.RegisterScript(self)  

        self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
        self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
        #self.ImageSeeder.Image = self.Image
        self.ImageSeeder.Image = self.InitializationImage
        self.ImageSeeder.Display = 0
        self.ImageSeeder.Execute()
        ##self.ImageSeeder.Display = 1
        self.ImageSeeder.BuildView()
 
        self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
        self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer
  
        if self.LevelSets != None:
            self.DisplayLevelSetSurface(self.LevelSets,0.0)
  
        self.vmtkImageInitialization = vmtkscripts.vmtkImageInitialization()
        #self.vmtkImageInitialization.Image = self.Image
        self.vmtkImageInitialization.Image = self.InitializationImage
        self.vmtkImageInitialization.vmtkRenderer = self.vmtkRenderer
        self.vmtkImageInitialization.ImageSeeder = self.ImageSeeder
        self.vmtkImageInitialization.SurfaceViewer = self.SurfaceViewer
        self.vmtkImageInitialization.NegateImage = self.NegateForInitialization
        self.vmtkImageInitialization.OwnRenderer = 0
 
        endSegmentation = 0
        while (endSegmentation == 0):
  
            if self.InitialLevelSets == None:
                self.vmtkImageInitialization.Execute()
                self.LevelSetsInput = self.vmtkImageInitialization.InitialLevelSets
#                self.IsoSurfaceValue = self.vmtkImageInitialization.IsoSurfaceValue
                self.vmtkImageInitialization.InitialLevelSets = None
#                self.vmtkImageInitialization.IsosurfaceValue = 0.0
                self.IsoSurfaceValue = 0.0
            else:
                self.LevelSetsInput = self.InitialLevelSets
                self.InitialLevelSets = None
                self.DisplayLevelSetSurface(self.LevelSetsInput,self.IsoSurfaceValue)
  
            endEvolution = False
            while not endEvolution:
  
                queryString = 'Please input parameters (type return to accept current values, \'e\' to end, \'q\' to quit):\nNumberOfIterations('+str(self.NumberOfIterations)+') [PropagationScaling('+str(self.PropagationScaling)+') CurvatureScaling('+str(self.CurvatureScaling)+') AdvectionScaling('+str(self.AdvectionScaling)+')]: '
                inputString = self.InputText(queryString,self.EvolutionParametersValidator)
  
                if inputString == 'q':
                    return
                elif inputString == 'e':
                    endEvolution = True
                elif inputString != '':
                    splitInputString = inputString.strip().split(' ')
                    if len(splitInputString) == 1:
                        self.NumberOfIterations = int(splitInputString[0])
                    elif len(splitInputString) == 4:
                        self.NumberOfIterations = int(splitInputString[0])
                        self.PropagationScaling = float(splitInputString[1])
                        self.CurvatureScaling = float(splitInputString[2])
                        self.AdvectionScaling = float(splitInputString[3])
                    else:
                        self.PrintLog('Wrong number of parameters.')
                        continue
  
                if endEvolution:
                    break
  
                self.LevelSetEvolution()
                self.DisplayLevelSetSurface(self.LevelSetsOutput)
  
                queryString = 'Accept result? (y/n): '
                inputString = self.InputText(queryString,self.YesNoValidator)
                if inputString == 'y':
                    endEvolution = True
                elif inputString == 'n':
                    endEvolution = False
  
            queryString = 'Merge branch? (y/n): '
            inputString = self.InputText(queryString,self.YesNoValidator)
            if inputString == 'y':
                self.MergeLevelSet()
            elif inputString == 'n':
                pass
 
            if self.LevelSets != None: 
                self.DisplayLevelSetSurface(self.LevelSets)
  
            queryString = 'Segment another branch? (y/n): '
            inputString = self.InputText(queryString,self.YesNoValidator)
            if inputString == 'y':
                endSegmentation = False
            elif inputString == 'n':
                endSegmentation = True
        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
Exemplo n.º 5
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if self.NegateImage:
            scalarRange = self.Image.GetScalarRange()
            negate = vtk.vtkImageMathematics()
            negate.SetInputData(self.Image)
            negate.SetOperationToMultiplyByK()
            negate.SetConstantK(-1.0)
            negate.Update()
            shiftScale = vtk.vtkImageShiftScale()
            shiftScale.SetInputConnection(negate.GetOutputPort())
            shiftScale.SetShift(scalarRange[1]+scalarRange[0])
            shiftScale.SetOutputScalarTypeToFloat()
            shiftScale.Update()
            self.Image = shiftScale.GetOutput()

        if self.Interactive:
            if not self.vmtkRenderer:
                self.vmtkRenderer = vmtkscripts.vmtkRenderer()
                self.vmtkRenderer.Initialize()
                self.OwnRenderer = 1

            self.vmtkRenderer.RegisterScript(self) 
 
            if not self.ImageSeeder: 
                self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
                self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
                self.ImageSeeder.Image = self.Image
                self.ImageSeeder.Display = 0
                self.ImageSeeder.Execute()
                ##self.ImageSeeder.Display = 1
                self.ImageSeeder.BuildView()
  
            if not self.SurfaceViewer:
                self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
                self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer
  
            initializationMethods = {
                                '0': self.CollidingFrontsInitialize,
                                '1': self.FastMarchingInitialize,
                                '2': self.ThresholdInitialize,
                                '3': self.IsosurfaceInitialize,
                                '4': self.SeedInitialize
                                }
  
            endInitialization = False
            while not endInitialization:
                queryString = 'Please choose initialization type: \n 0: colliding fronts;\n 1: fast marching;\n 2: threshold;\n 3: isosurface;\n 4: seed\n '
                initializationType = self.InputText(queryString,self.InitializationTypeValidator)
                initializationMethods[initializationType]()
                self.DisplayLevelSetSurface(self.InitialLevelSets)
                queryString = 'Accept initialization? (y/n): '
                inputString = self.InputText(queryString,self.YesNoValidator)
                if inputString == 'y':
                    self.MergeLevelSets()
                    self.DisplayLevelSetSurface(self.MergedInitialLevelSets)
                queryString = 'Initialize another branch? (y/n): '
                inputString = self.InputText(queryString,self.YesNoValidator)
                if inputString == 'y':
                    endInitialization = False
                elif inputString == 'n':
                    endInitialization = True

            self.InitialLevelSets = self.MergedInitialLevelSets
            self.MergedInitialLevelSets = None

        else:
            if self.Method == "collidingfronts":
                self.CollidingFrontsInitialize()
            elif self.Method == "fastmarching":
                self.FastMarchingInitialize()
            elif self.Method == "threshold":
                self.ThresholdInitialize()
            elif self.Method == "isosurface":
                self.IsosurfaceInitialize()
            elif self.Method == "seeds":
                self.SeedInitialize()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()