#============================================================================== # # Project: SharpImage # Module: Bilateral.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 Denoising library clr.AddReference("ManagedITK.NoiseFilters") from itk import * class BilateralScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Bilateral" Help = """Performs denoising of the input image by bluring using both domain and range neighbourhoods. Two Gaussian kernels (one for the image domain and one for the image range) are used to smooth homogenious regions, and yet preserve edges. The result is similar to anisotropic diffusion but the implementation in non-iterative.""" Parameters = """(List) DomainSigma = the domain Gaussian sigma. ([5.0,5.0,.]) (double) RangeSigma = the range Gaussian sigma. (5.0) (itkSize) Radius = the radius of the Gaussian kernel.""" DomainSigma = None RangeSigma = 5.0 Radius = None # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: # Setup self.StartedWork() self.WriteInputName() filterBilateral = itkBilateralImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterBilateral ) filterBilateral.SetInput( self.Input ) # Set domain if (self.DomainSigma == None): self.DomainSigma = [None] * self.Input.Dimension for i in range( self.Input.Dimension ): self.DomainSigma[i] = 5.0 filterBilateral.DomainSigma = System.Array[Double]( self.DomainSigma ) self.WriteLineToConsole( "DomainSigma=" + self.ArrayToString(filterBilateral.DomainSigma ) ) # Set range filterBilateral.RangeSigma = self.RangeSigma self.WriteLineToConsole( "RangeSigma=" + filterBilateral.RangeSigma.ToString() ) # Set radius if (self.Radius != None): filterBilateral.AutomaticKernelSize = False filterBilateral.Radius = self.Radius self.WriteLineToConsole( "Radius=" + filterBilateral.Radius.ToString() ) # Update and finish filterBilateral.UpdateLargestPossibleRegion() filterBilateral.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterBilateral ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )