#============================================================================== # # Project: SharpImage # Module: MinMaxCalc.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 ThreadedScript from ThreadedScript import * # Add reference and import Calculators library clr.AddReference("ManagedITK.Calculators") from itk import * class MinMaxCalcScript(ThreadedScriptObject): # ------------------------------------------------------------------------- Name = "MinMaxCalc" Help = """This calculator computes the minimum and the maximum intensity values of an image. The values are displayed in the script console.""" Parameters = """None""" Renderer = None Input = None # ------------------------------------------------------------------------- def Initialise(self): """ Initialise the environment for running this script. """ """ NOTE: This function is invoked on the main UI thread. """ ThreadedScriptObject.Initialise(self) self.Renderer = self.ParentApplication.CurrentRenderer self.Input = self.Renderer.Inputs[0] def ThreadedDoWork(self): """ Perform the main functions of the script. """ """ NOTE: This function is invoked on a background thread. """ try: self.StartedWork() self.WriteImageName( "Input=", self.Input ) calcMinMax = itkMinimumMaximumImageCalculator.New( self.Input ) calcMinMax.SetImage( self.Input ) calcMinMax.Compute() self.WriteLineToConsole( "Minimum=" + calcMinMax.Minimum.ToString() ) self.WriteLineToConsole( "Maximum=" + calcMinMax.Maximum.ToString() ) self.Input.DisconnectPipeline() self.DisposeOfObject( calcMinMax ) self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )