#============================================================================== # # Project: SharpImage # Module: ZeroCrossing.py # Language: IronPython # Author: Dan Mueller # $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ # $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 Edges library clr.AddReference("ManagedITK.EdgeFilters") from itk import * class ZeroCrossingScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "ZeroCrossing" Help = """Finds the closest pixel to the zero-crossings (sign changes) in the input image.""" Parameters = """(pixel) ForegroundValue = the output foreground value. (255.0) (pixel) BackgroundValue = the output background value. (0.0)""" ForegroundValue = 255.0 BackgroundValue = 0.0 # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: self.StartedWork() self.WriteInputName() filterZeroCrossing = itkZeroCrossingImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterZeroCrossing ) filterZeroCrossing.SetInput( self.Input ) filterZeroCrossing.ForegroundValue = itkPixel( self.Output.PixelType, self.ForegroundValue ) filterZeroCrossing.BackgroundValue = itkPixel( self.Output.PixelType, self.BackgroundValue ) self.WriteLineToConsole( "ForegroundValue=" + self.ForegroundValue.ToString() ) self.WriteLineToConsole( "BackgroundValue=" + self.BackgroundValue.ToString() ) filterZeroCrossing.UpdateLargestPossibleRegion() filterZeroCrossing.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterZeroCrossing ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )