#============================================================================== # # Project: SharpImage # Module: MorphologicalErode.py # Language: IronPython # Author: Dan Mueller # Date: $Date$ # Revision: $Revision$ # # 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.FastMorphologicalFilters") from itk import * class FastMorphologicalErodeScript(ImageToImageScriptObject): # ------------------------------------------------------------------------- Name = "FastMorphologicalErode" Help = """Computes the fast grayscale morphological erosion of an image. This script takes the minimum of all pixels within a given structuring element.""" Parameters = """(itkSize) KernelRadius = the radius of the ball. (itkSize(1,1,.)) (itkFlatStructuringElement) Kernel = the structuring element. (Box) (FastMorphologyEnum) Algorithm = Basic, Histogram, Anchor, or VHGW. (VHGW)""" KernelRadius = None Kernel = None Algorithm = FastMorphologyEnum.VHGW # ------------------------------------------------------------------------- def ThreadedDoWork(self): """ Perform the main functions of the script on a background thread. """ try: self.StartedWork() self.WriteInputName() filterErode = itkGrayscaleErodeImageFilter.New( self.Input, self.Output ) self.AddEventHandlersToProcessObject( filterErode ) filterErode.SetInput( self.Input ) if (self.KernelRadius == None): self.KernelRadius = itkSize( self.Input.Dimension ) self.KernelRadius.Fill( 1 ) if (self.Kernel == None): self.Kernel = itkFlatStructuringElement.Box( self.KernelRadius ); filterErode.Kernel = self.Kernel filterErode.Algorithm = self.Algorithm self.WriteLineToConsole( "Kernel=" + self.Kernel.ToString() ) self.WriteLineToConsole( "Algorithm=" + self.Algorithm.ToString() ) filterErode.UpdateLargestPossibleRegion() filterErode.GetOutput( self.Output ) self.DisconnectInputAndOutput() self.DisposeOfObject( filterErode ) self.WriteOutputName() self.FinishedWork( True ) except Exception, ex: self.HandleException( ex ) self.FinishedWork( False ) self.Finalise( )