#============================================================================== # # Project: SharpImage # Module: Gradient.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 Common library clr.AddReference("ManagedITK.GradientFilters") from itk import * class GradientScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Gradient" Help = """Computes the gradient of an image region at each pixel.""" Parameters = """UseImageSpacing = indicates use of image spacing. (True)""" UseImageSpacing = True # ------------------------------------------------------------------------- def Initialise(self): """ Initialise the environment for running this script. """ """ NOTE: This function is invoked on the main UI thread. """ try: ImageToImageScriptObject.Initialise( self ) pixelType = itkPixelTypeEnum.Float pixelArray = itkPixelArrayEnum.ArrayCovariantVector pixelComponents = self.Input.Dimension self.Output = itkImage.New( itkPixelType(pixelType, pixelArray, pixelComponents), self.Input.Dimension ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( ) def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: self.StartedWork() self.WriteInputName() filterGrad = itkGradientImageFilter.New( self.Input, itkPixelType.F, itkPixelType.F ) self.AddEventHandlersToProcessObject( filterGrad ) filterGrad.SetInput( self.Input ) filterGrad.UseImageSpacing = self.UseImageSpacing self.WriteLineToConsole( "UseImageSpacing=" + self.UseImageSpacing.ToString() ) filterGrad.UpdateLargestPossibleRegion() filterGrad.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterGrad ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )