#============================================================================== # # Project: SharpImage # Module: ShiftScale.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 ShiftScaleScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "ShiftScale" Help = """Applies a linear transformation by firstly adding Shift to each pixel, then multiplying each pixel by Scale. This filter works for both scalar and array pixels.""" Parameters = """(double) Shift = the amount to shift (0.0) (double) Scale = the scale factor (1.0)""" Shift = 0.0 Scale = 1.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() filterShiftScale = None if (self.Input.PixelType.IsArray): filterShiftScale = itkVectorShiftScaleImageFilter.New( self.Input, self.Output ) else: filterShiftScale = itkShiftScaleImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterShiftScale ) filterShiftScale.SetInput( self.Input ) filterShiftScale.Shift = self.Shift filterShiftScale.Scale = self.Scale self.WriteLineToConsole( "Shift=" + self.Shift.ToString() ) self.WriteLineToConsole( "Scale=" + self.Scale.ToString() ) filterShiftScale.UpdateLargestPossibleRegion() filterShiftScale.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterShiftScale ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )