#============================================================================== # # Project: SharpImage # Module: Sigmoid.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 Intensity library clr.AddReference("ManagedITK.IntensityFilters") from itk import * class SigmoidScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Sigmoid" Help = """Applies the linear sigmoid transform function to each pixel.""" Parameters = """(double) Alpha = the alpha value. (1.0) (double) Beta = the beta value. (0.0) (pixel) OutputMinimum = the output image minimum. (0.0) (pixel) OutputMaximum = the output image maximum. (255.0)""" OutputMinimum = 0.0 OutputMaximum = 255.0 Alpha = 1.0 Beta = 0.0 # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ try: self.StartedWork() self.WriteInputName() filterSigmoid = itkSigmoidImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterSigmoid ) filterSigmoid.SetInput( self.Input ) filterSigmoid.Alpha = self.Alpha filterSigmoid.Beta = self.Beta pixelOutputMinimum = itkPixel( self.Output.PixelType, self.OutputMinimum ) pixelOutputMaximum = itkPixel( self.Output.PixelType, self.OutputMaximum ) filterSigmoid.OutputMinimum = pixelOutputMinimum filterSigmoid.OutputMaximum = pixelOutputMaximum self.WriteLineToConsole( "Alpha=" + self.Alpha.ToString() ) self.WriteLineToConsole( "Beta=" + self.Beta.ToString() ) self.WriteLineToConsole( "OutputMinimum=" + pixelOutputMinimum.ToString() ) self.WriteLineToConsole( "OutputMaximum=" + pixelOutputMaximum.ToString() ) filterSigmoid.UpdateLargestPossibleRegion() filterSigmoid.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterSigmoid ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )