#============================================================================== # # Project: SharpImage # Module: DiscreteGaussian.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.NoiseFilters") from itk import * class DiscreteGaussianScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "DiscreteGaussian" Help = """Blurs an image by separable convolution with discrete gaussian kernels. This filter performs Gaussian blurring by separable convolution of an image and a discrete Gaussian operator (kernel).""" Parameters = """(double) Variance = the variance parameter of the smoothing kernel. (0.1) (double) MaximumError = truncation of kernel will not exceed this value. (0.01) (int) MaximumKernelWidth = the maximum width of the kernel, overrides MaximumError. (32) (bool) UseImageSpacing = Specifies if the image spacing should be used computing the distance. (True)""" Variance = 0.1 MaximumError = 0.01 MaximumKernelWidth = 32 UseImageSpacing = True # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: self.StartedWork() self.WriteInputName() filterSmooth = itkDiscreteGaussianImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterSmooth ) filterSmooth.SetInput( self.Input ) filterSmooth.SetVariance( self.Variance ) filterSmooth.SetMaximumError( self.MaximumError ) filterSmooth.MaximumKernelWidth = self.MaximumKernelWidth filterSmooth.UseImageSpacing = self.UseImageSpacing self.WriteLineToConsole( "Variance=" + self.Variance.ToString() ) self.WriteLineToConsole( "MaximumError=" + self.MaximumError.ToString() ) self.WriteLineToConsole( "MaximumKernelWidth=" + self.MaximumKernelWidth.ToString() ) self.WriteLineToConsole( "UseImageSpacing=" + self.UseImageSpacing.ToString() ) filterSmooth.UpdateLargestPossibleRegion() filterSmooth.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterSmooth ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )