#============================================================================== # # Project: SharpImage # Module: ExtractComponent.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 relevent class import ImageToImageScript from ImageToImageScript import * # Add reference and import Compose library clr.AddReference("ManagedITK.Image.Compose") from itk import * class ExtractComponentScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "ExtractComponent" Help = """Extracts a component from a vector image.""" Parameters = """(int) Index = the index of the component to extract. (0)""" Index = 0 # ------------------------------------------------------------------------- def Initialise(self): """ Initialise the environment for running this script. """ """ NOTE: This function is invoked on the main UI thread. """ try: ThreadedScriptObject.Initialise( self ) self.Renderer = self.ParentApplication.CurrentRenderer self.Input = self.Renderer.Inputs[0] outputPixelType = itkPixelType( self.Input.PixelType.TypeAsEnum ) self.Output = itkImage.New( outputPixelType, self.Input.Dimension ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) ScriptObject.Finalise( self ) def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: self.StartedWork() # Setup and run the filter filterExtract = itkVectorIndexSelectionCastImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterExtract ) filterExtract.SetInput( self.Input ) filterExtract.Index = self.Index self.WriteLineToConsole( "Index=" + self.Index.ToString() ) filterExtract.UpdateLargestPossibleRegion() filterExtract.GetOutput( self.Output ) # Clean up and return self.DisconnectInputAndOutput() self.DisposeOfObject( filterExtract ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )