#============================================================================== # # Project: SharpImage # Module: Canny.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 Edges library clr.AddReference("ManagedITK.EdgeFilters") from itk import * class CannyScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Canny" Help = """Applies the Canny edge detection algorithm to the input image.""" Parameters = """(pixel) UpperThreshold = upper threshold value for detected edges (5.0) (pixel) LowerThreshold = lower threshold value for detected edges (0.0) (pixel) OutsideValue = the value for pixels outside a detected edge (0.0) (double) Variance = the variance parameter for Gaussian smoothing (0.1) (double) MaximumError = the maximum error parameter for Gaussian smoothing (0.01)""" LowerThreshold = 0.0 UpperThreshold = 5.0 OutsideValue = 0.0 Variance = 0.1 MaximumError = 0.01 # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ try: self.StartedWork() self.WriteInputName() filterCanny = itkCannyEdgeDetectionImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterCanny ) filterCanny.SetInput( self.Input ) filterCanny.LowerThreshold = itkPixel( self.Output.PixelType, self.LowerThreshold ) filterCanny.UpperThreshold = itkPixel( self.Output.PixelType, self.UpperThreshold ) filterCanny.OutsideValue = itkPixel( self.Output.PixelType, self.OutsideValue ) filterCanny.SetVariance( self.Variance ) filterCanny.SetMaximumError( self.MaximumError ) self.WriteLineToConsole( "LowerThreshold=" + self.LowerThreshold.ToString() ) self.WriteLineToConsole( "UpperThreshold=" + self.UpperThreshold.ToString() ) self.WriteLineToConsole( "OutsideValue=" + self.OutsideValue.ToString() ) self.WriteLineToConsole( "Variance=" + self.Variance.ToString() ) self.WriteLineToConsole( "MaximumError=" + self.MaximumError.ToString() ) filterCanny.UpdateLargestPossibleRegion() filterCanny.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterCanny ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )