#============================================================================== # # Project: SharpImage # Module: Vesselness.py # Language: IronPython # Author: Dan Mueller # $Date$ # $Revision$ # # Copyright (c) Queensland University of Technology (QUT) 2007. # All rights reserved. # # This software is distributed WITHOUT ANY WARRANTY; without even # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the above copyright notices for more information. # #============================================================================== # Import the base script class import ImageToImageScript from ImageToImageScript import * # Add CLR reference and import required libraries clr.AddReference("ManagedITK.Filtering.Vesselness") from itk import * class VesselnessScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Vesselness" Help = """Implements a Hessian-based line enhancement filter for segmenting\r\ tubular objects. The input image must be a 3-D image.""" Parameters = "(double) Sigma = the variance of the Gaussian (Default=1.0)\r\ (double) Alpha1 = a control parameter for the vesselness measure (Default=0.5)\r\ (double) Alpha2 = a control parameter for the vesselness measure (Default=2.0)\r\ (bool) NormalizeAcrossScale = indicates if the scale is used (Default=False)" Sigma = 1.0 Alpha1 = 0.5 Alpha2 = 2.0 NormalizeAcrossScale = False # ------------------------------------------------------------------------- def Initialise(self): """ Initialise the environment for running this script. NOTE: This function is invoked on the main UI thread. """ ImageToImageScriptObject.Initialise( self ) # Validate the input is real and 3-D if ( self.Input.Dimension != 3 ): raise ArgumentException( "The input image must have 3 dimensions" ) if ( not self.Input.PixelType.IsReal ): raise ArgumentException( "The input image must be a real pixel type (eg. float)" ) def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: # Start self.StartedWork() self.WriteInputName() # Compute hessian filterHessian = itkHessianRecursiveGaussianImageFilter.New( self.Input ) self.AddEventHandlersToProcessObject( filterHessian ) filterHessian.SetInput( self.Input ) filterHessian.Sigma = self.Sigma filterHessian.NormalizeAcrossScale = self.NormalizeAcrossScale self.WriteLineToConsole( "Sigma=" + self.Sigma.ToString() ) self.WriteLineToConsole( "NormalizeAcrossScale=" + self.NormalizeAcrossScale.ToString() ) # Compute vesselness filterVesselness = itkHessian3DToVesselnessMeasureImageFilter.New( itkPixelType.F ) self.AddEventHandlersToProcessObject( filterVesselness ) filterVesselness.SetInput( filterHessian.GetOutput() ) filterVesselness.Alpha1 = self.Alpha1 filterVesselness.Alpha2 = self.Alpha2 self.WriteLineToConsole( "Alpha1=" + self.Alpha1.ToString() ) self.WriteLineToConsole( "Alpha2=" + self.Alpha2.ToString() ) filterVesselness.UpdateLargestPossibleRegion( ) filterVesselness.GetOutput( self.Output ) # Clean up and finish self.DisconnectInputAndOutput() self.DisposeOfObject( filterHessian ) self.DisposeOfObject( filterVesselness ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )