#============================================================================== # # Project: SharpImage # Module: SignedMaurerDistance.py # Language: IronPython # Author: Dan Mueller # Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ # Revision: $Revision: 2 $ # # 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 reference and import DistanceMap library clr.AddReference("ManagedITK.DistanceMaps") from itk import * class SignedMaurerDistanceScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "SignedMaurerDistance" Help = """Creates a map of the Euclidean distance to the nearest object. The input should be a floating-point binary image with min=0 and max=255, and the output is a signed floating-point distance map.""" Parameters = """(bool) InsideIsPositive = Indicates if the inside value is positve in the map. (True) (bool) UseImageSpacing = Specifies if the image spacing is used. (True) (pixel) BackgroundValue = Specifies the background of the image. (0)""" InsideIsPositive = True UseImageSpacing = True BackgroundValue = None # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ try: self.StartedWork() self.WriteInputName() filterDistance = itkSignedMaurerDistanceMapImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterDistance ) filterDistance.SetInput( self.Input ) filterDistance.SquaredDistance = False filterDistance.InsideIsPositive = self.InsideIsPositive filterDistance.UseImageSpacing = self.UseImageSpacing if (self.BackgroundValue != None): filterDistance.BackgroundValue = itkPixel( self.Input.PixelType, self.BackgroundValue ) self.WriteLineToConsole( "InsideIsPositive=" + self.InsideIsPositive.ToString() ) self.WriteLineToConsole( "UseImageSpacing=" + self.UseImageSpacing.ToString() ) self.WriteLineToConsole( "BackgroundValue=" + filterDistance.BackgroundValue.ToString() ) filterDistance.UpdateLargestPossibleRegion() filterDistance.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterDistance ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )