#============================================================================== # # Project: SharpImage # Module: GradientMagnitudeRecursiveGaussianWithForm.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 SlicePipelineScript from SlicePipelineScript import * # Add reference and import Common library clr.AddReference("ManagedITK.GradientFilters") from itk import * class GradientMagnitudeRecursiveGaussianWithFormScript(SlicePipelineScriptObject): # ------------------------------------------------------------------------- Name = "GradientMagnitudeRecursiveGaussianWithForm" Help = """Computes the magnitude of the gradient of an image by convolution with the first derivative of a Gaussian. The Sigma parameter is specified using a slider.""" Parameters = """(bool) NormalizeAcrossScale = indicates if the scale is used. (False)""" NormalizeAcrossScale = False # ------------------------------------------------------------------------- def AddVariablesToForm(self): """ Add the required variables to the form. """ defaultSigma = 1.0 self.Form.AddVariable( "Sigma", defaultSigma, 0.01, 10.0, 0.01 ) def CreatePipeline(self, isSlice): """ Set self.Pipeline to an instance of an itkPipeline. If isSlice is True the events are watched, otherwise events are NOT watched. """ self.Pipeline = itkGradientMagnitudeRecursiveGaussianImageFilter.New( self.Input, self.Output ) if (isSlice): self.Pipeline.RemoveAllObservers( ) else: self.AddEventHandlersToProcessObject( self.Pipeline ) def ApplyPipeline(self, isSlice): """ Apply self.Pipeline by setting the input, setting the filter parameters (stored in self.Variables), updating the pipeline, getting the output, and disconnecting the inputs and outputs. If isSlice is True the pipeline is being applied to the current slice only, otherwise the pipeline is being applied to whole image (eg. a 2D or 3D image). """ # Check the pipeline was not null if (self.Pipeline == None): return # Setup the pipeline inputs and parameters self.Pipeline.SetInput( self.Input ) self.Pipeline.NormalizeAcrossScale = self.NormalizeAcrossScale self.Pipeline.Sigma = self.Variables["Sigma"] # Write the parameters if not isSlice if (not isSlice): self.WriteLineToConsole( "NormalizeAcrossScale=" + self.NormalizeAcrossScale.ToString() ) self.WriteLineToConsole( "Sigma=" + self.Variables["Sigma"].ToString() ) # Update the pipeline and get output self.Pipeline.Update( ) self.Pipeline.GetOutput( self.Output ) # Disconnect inputs/outputs self.DisconnectInputAndOutput( )