#============================================================================== # # Project: SharpImage # Module: RescaleIntensity.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 RescaleIntensityScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "RescaleIntensity" Help = """Applies a linear transformation to the intensity levels of the input Image. RescaleIntensityImageFilter applies a pixel-wise linear transformation to the intensity values of input image pixels. The linear transformation is defined by the user in terms of the minimum and maximum values that the output image should have.""" Parameters = """(pixel) OutputMinimum = the output image minimum (0) (pixel) OutputMaximum = the output image maximum (255) (itkPixelType) OutputPixelType = the output pixel type (input)""" OutputMinimum = 0 OutputMaximum = 255 OutputPixelType = None # ------------------------------------------------------------------------- def Initialise(self): """ Initialise the environment for running this script. """ """ NOTE: This function is invoked on the main UI thread. """ ImageToImageScriptObject.Initialise( self ) if (self.OutputPixelType == None): self.Output = itkImage.New( self.Input ) else: self.Output = itkImage.New( self.OutputPixelType, self.Input.Dimension ) def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ try: self.StartedWork() self.WriteInputName() filterRescale = itkRescaleIntensityImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterRescale ) filterRescale.SetInput( self.Input ) filterRescale.OutputMinimum = itkPixel( self.Output.PixelType, self.OutputMinimum ) filterRescale.OutputMaximum = itkPixel( self.Output.PixelType, self.OutputMaximum ) self.WriteLineToConsole( "OutputMinimum=" + filterRescale.OutputMinimum.ToString() ) self.WriteLineToConsole( "OutputMaximum=" + filterRescale.OutputMaximum.ToString() ) filterRescale.UpdateLargestPossibleRegion() filterRescale.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterRescale ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )