#============================================================================== # # Project: SharpImage # Module: Flip.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 Transform library clr.AddReference("ManagedITK.Transforms") from itk import * class FlipScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Flip" Help = """Flips an image across user specified axes. Example: Flip Axes=[False,True]""" Parameters = """(List) Axes = the axes to flip. ([True,True,.])""" Axes = [] # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: # Start self.StartedWork() # Set the default flip axes if (len(self.Axes) == 0): for i in range( self.Input.Dimension ): self.Axes[i] = True # Setup and run filter self.WriteInputName() filterFlip = itkFlipImageFilter.New( self.Input ) self.AddEventHandlersToProcessObject( filterFlip ) filterFlip.SetInput( self.Input ) filterFlip.FlipAxes = System.Array[Boolean]( self.Axes ) self.WriteLineToConsole( "FlipAxes=" + self.ArrayToString(self.Axes) ) filterFlip.UpdateLargestPossibleRegion() filterFlip.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterFlip ) # Finish off self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )