#============================================================================== # # Project: SharpImage # Module: WindowLevel.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 WindowLevelScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "WindowLevel" Help = """Applies a linear transformation to the intensity levels of the input image that are inside a user-defined interval. Values below this interval are mapped to a constant (itkPixelType.MinValue). Values above the interval are mapped to another constant (itkPixelType.MaxValue). This operation is very common in visualization, and can also be applied as a convenient preprocessing operation for image segmentation.""" Parameters = """(pixel) Window = the window value. (pixel) Level = the level value. (pixel) OutputMinimum = the output image minimum. (pixel) OutputMaximum = the output image maximum.""" Window = None Level = None OutputMinimum = None OutputMaximum = 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() filterWindowLevel = itkIntensityWindowingImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterWindowLevel ) filterWindowLevel.SetInput( self.Input ) pixelWindow = itkPixel( self.Input.PixelType, self.Window ) pixelLevel = itkPixel( self.Input.PixelType, self.Level ) filterWindowLevel.SetWindowLevel( pixelWindow, pixelLevel ) if (self.OutputMinimum != None): filterWindowLevel.OutputMinimum = itkPixel( self.Output.PixelType, self.OutputMinimum ) if (self.OutputMaximum != None): filterWindowLevel.OutputMaximum = itkPixel( self.Output.PixelType, self.OutputMaximum ) self.WriteLineToConsole( "Window=" + self.Window.ToString() ) self.WriteLineToConsole( "Level=" + self.Level.ToString() ) self.WriteLineToConsole( "OutputMinimum=" + filterWindowLevel.OutputMinimum.ToString() ) self.WriteLineToConsole( "OutputMaximum=" + filterWindowLevel.OutputMaximum.ToString() ) filterWindowLevel.UpdateLargestPossibleRegion() filterWindowLevel.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterWindowLevel ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )