#============================================================================== # # Project: SharpImage # Module: ZeroCrossingEdge.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 ZeroCrossingEdgeScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "ZeroCrossingEdge" Help = """Applies a Laplacian zero-crossing edge detection algorithm to the input image.""" Parameters = """(double) Variance = the variance parameter for Gaussian smoothing. (0.1) (double) MaximumError = the maximum error parameter for Gaussian smoothing. (0.01) (pixel) ForegroundValue = the output foreground value. (255.0) (pixel) BackgroundValue = the output background value. (0.0)""" Variance = 0.1 MaximumError = 0.01 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 = itkZeroCrossingBasedEdgeDetectionImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterZeroCrossing ) filterZeroCrossing.SetInput( self.Input ) filterZeroCrossing.SetVariance( self.Variance ) filterZeroCrossing.SetMaximumError( self.MaximumError ) filterZeroCrossing.ForegroundValue = itkPixel( self.Output.PixelType, self.ForegroundValue ) filterZeroCrossing.BackgroundValue = itkPixel( self.Output.PixelType, self.BackgroundValue ) self.WriteLineToConsole( "Variance=" + self.Variance.ToString() ) self.WriteLineToConsole( "MaximumError=" + self.MaximumError.ToString() ) 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( )