#============================================================================== # # Project: SharpImage # Module: MorphologicalMultiscaleOpen.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 Morphology library clr.AddReference("ManagedITK.MultiscaleMorphologicalFilters") from itk import * class MorphologicalMultiscaleOpenScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "MorphologicalMultiscaleOpen" Help = """Computes the multi-scale greyscale morphological opening of an image. This filter enhances objects of different sizes, as defined by the schedule and weights. Eg. MorphologicalMultiscaleOpen Schedule=[2,4,6] Weights=[2.0,1.0,0.25]""" Parameters = """(uint) NumberOfScales = the number of scales. (4) (List) Schedule = the schedule of structing element radii. ([1,2,3,4]) (List) Weights = the weights for each scale. ([2.0,1.5,1.0,0.5])""" NumberOfScales = 4 Schedule =[1,2,3,4] Weights = [2.0,1.5,1.0,0.5] # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: self.StartedWork() self.WriteInputName() filterOpen = itkMultiscaleGrayscaleOpeningImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterOpen ) filterOpen.SetInput( self.Input ) # Display parameters self.WriteLineToConsole( "NumberOfScales=" + self.NumberOfScales.ToString() ) self.WriteLineToConsole( "Schedule=" + self.ArrayToString(self.Schedule) ) self.WriteLineToConsole( "Weights=" + self.ArrayToString(self.Weights) ) # Setup and run filter filterOpen.NumberOfScales = self.NumberOfScales filterOpen.Schedule = System.Array[UInt32](self.Schedule) filterOpen.Weights = System.Array[Double](self.Weights) filterOpen.UpdateLargestPossibleRegion() filterOpen.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterOpen ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )