#============================================================================== # # Project: SharpImage # Module: Mean.py # Language: IronPython # Author: Dan Mueller # Date: $Date: 2007-07-06 11:52:27 +1000 (Fri, 06 Jul 2007) $ # Revision: $Revision: 5 $ # # 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 MeanScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Mean" Help = """Computes an image where a given pixel is the mean value of the pixels in a neighborhood about the corresponding input pixel. """ Parameters = """(itkSize) Radius = the size of the neighborhood. (itkSize(2,2,.))""" Radius = None # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ try: self.StartedWork() self.WriteInputName() filterMean = itkMeanImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterMean ) filterMean.SetInput( self.Input ) if (self.Radius == None): self.Radius = itkSize( self.Input.Dimension ) self.Radius.Fill( 2 ) self.WriteLineToConsole("Radius= " + self.Radius.ToString()) filterMean.Radius = self.Radius filterMean.UpdateLargestPossibleRegion() filterMean.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterMean ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )