#============================================================================== # # Project: SharpImage # Module: ChamferDistance.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 Topology library clr.AddReference("ManagedITK.Image.Topology") from itk import * class ChamferDistanceScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "ChamferDistance" Help = """Computes the the chamfer distance.""" Parameters = """(bool) InsideObject = sets if the distance is inside or outside the object. (True)""" InsideObject = True # ------------------------------------------------------------------------- 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 = itkChamferDistanceTransformImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterDistance ) filterDistance.SetInput( self.Input ) filterDistance.DistanceFromObject = not self.InsideObject self.WriteLineToConsole( "InsideObject=" + self.InsideObject.ToString() ) filterDistance.SetWeight(0, itkPixel(self.Output.PixelType, 3) ) filterDistance.SetWeight(1, itkPixel(self.Output.PixelType, 4) ) if (self.Input.Dimension == 3): filterDistance.SetWeight(2, itkPixel(self.Output.PixelType, 5) ) 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( )