#============================================================================== # # Project: SharpImage # Module: Orient.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.Image.Transform") from itk import * class OrientScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "Orient" Help = """Orientate a 3D image with respect to anatomical features. If the Given orientation is not provided, it is automatically computed by the direction cosines. The directions are labeled in terms of following pairs: - Left and Right - Anterior and Posterior (front and back) - Inferior and Superior (bottom and top) Eg: "RIP": Right-to-Left varies fastest, Inferior-to-Superior varies second fastest, Posterior-to-Anterior varies slowest. Common orientations: "RAI"=Axial, "RSA"=Coronal, "ASL"=Sagittal""" Parameters = """(string) Desired = a string of the desired output orientation. (string) Given = a string of the orientation of the input image.""" Given = None Desired = None # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: # Setup self.StartedWork() self.WriteInputName() # Create the orient filter filterOrient = itkOrientImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterOrient ) filterOrient.SetInput( self.Input ) # Get the given and desired orientations OrientEnum = itkSpatialOrientationEnum if (self.Given == None): filterOrient.UseImageDirection = True self.WriteLineToConsole( "Using image direction cosines to compute given orientation..." ) else: self.Given = Enum.Parse( OrientEnum, self.Given, True ) filterOrient.GivenCoordinateOrientation = self.Given if (self.Desired == None): raise ArgumentException( "A desired orientation must be provided." ) else: self.Desired = Enum.Parse( OrientEnum, self.Desired, True ) filterOrient.DesiredCoordinateOrientation = self.Desired # Peform the work filterOrient.UpdateLargestPossibleRegion() filterOrient.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterOrient ) self.WriteOutputNameWithSuffix( self.Desired.ToString() ) self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )