OpenMS
MorphologicalFilter Class Reference

This class implements baseline filtering operations using methods from mathematical morphology. More...

#include <OpenMS/FILTERING/BASELINE/MorphologicalFilter.h>

Inheritance diagram for MorphologicalFilter:
[legend]
Collaboration diagram for MorphologicalFilter:
[legend]

Public Member Functions

 MorphologicalFilter ()
 Constructor. More...
 
 ~MorphologicalFilter () override
 Destructor. More...
 
template<typename InputIterator , typename OutputIterator >
void filterRange (InputIterator input_begin, InputIterator input_end, OutputIterator output_begin)
 Applies the morphological filtering operation to an iterator range. More...
 
void filter (MSSpectrum &spectrum)
 Applies the morphological filtering operation to an MSSpectrum. More...
 
void filterExperiment (PeakMap &exp)
 Applies the morphological filtering operation to an MSExperiment. More...
 
- Public Member Functions inherited from ProgressLogger
 ProgressLogger ()
 Constructor. More...
 
virtual ~ProgressLogger ()
 Destructor. More...
 
 ProgressLogger (const ProgressLogger &other)
 Copy constructor. More...
 
ProgressLoggeroperator= (const ProgressLogger &other)
 Assignment Operator. More...
 
void setLogType (LogType type) const
 Sets the progress log that should be used. The default type is NONE! More...
 
LogType getLogType () const
 Returns the type of progress log being used. More...
 
void startProgress (SignedSize begin, SignedSize end, const String &label) const
 Initializes the progress display. More...
 
void setProgress (SignedSize value) const
 Sets the current progress. More...
 
void endProgress (UInt64 bytes_processed=0) const
 
void nextProgress () const
 increment progress by 1 (according to range begin-end) More...
 
- Public Member Functions inherited from DefaultParamHandler
 DefaultParamHandler (const String &name)
 Constructor with name that is displayed in error messages. More...
 
 DefaultParamHandler (const DefaultParamHandler &rhs)
 Copy constructor. More...
 
virtual ~DefaultParamHandler ()
 Destructor. More...
 
DefaultParamHandleroperator= (const DefaultParamHandler &rhs)
 Assignment operator. More...
 
virtual bool operator== (const DefaultParamHandler &rhs) const
 Equality operator. More...
 
void setParameters (const Param &param)
 Sets the parameters. More...
 
const ParamgetParameters () const
 Non-mutable access to the parameters. More...
 
const ParamgetDefaults () const
 Non-mutable access to the default parameters. More...
 
const StringgetName () const
 Non-mutable access to the name. More...
 
void setName (const String &name)
 Mutable access to the name. More...
 
const std::vector< String > & getSubsections () const
 Non-mutable access to the registered subsections. More...
 

Protected Member Functions

template<typename InputIterator , typename OutputIterator >
void applyErosion_ (Int struc_size, InputIterator input, InputIterator input_end, OutputIterator output)
 Applies erosion. This implementation uses van Herk's method. Only 3 min/max comparisons are required per data point, independent of struc_size. More...
 
template<typename InputIterator , typename OutputIterator >
void applyDilation_ (Int struc_size, InputIterator input, InputIterator input_end, OutputIterator output)
 Applies dilation. This implementation uses van Herk's method. Only 3 min/max comparisons are required per data point, independent of struc_size. More...
 
template<typename InputIterator , typename OutputIterator >
void applyErosionSimple_ (Int struc_size, InputIterator input_begin, InputIterator input_end, OutputIterator output_begin)
 Applies erosion. Simple implementation, possibly faster if struc_size is very small, and used in some special cases. More...
 
template<typename InputIterator , typename OutputIterator >
void applyDilationSimple_ (Int struc_size, InputIterator input_begin, InputIterator input_end, OutputIterator output_begin)
 Applies dilation. Simple implementation, possibly faster if struc_size is very small, and used in some special cases. More...
 
- Protected Member Functions inherited from DefaultParamHandler
virtual void updateMembers_ ()
 This method is used to update extra member variables at the end of the setParameters() method. More...
 
void defaultsToParam_ ()
 Updates the parameters after the defaults have been set in the constructor. More...
 

Protected Attributes

UInt struct_size_in_datapoints_
 Member for struct size in data points. More...
 
- Protected Attributes inherited from ProgressLogger
LogType type_
 
time_t last_invoke_
 
ProgressLoggerImplcurrent_logger_
 
- Protected Attributes inherited from DefaultParamHandler
Param param_
 Container for current parameters. More...
 
Param defaults_
 Container for default parameters. This member should be filled in the constructor of derived classes! More...
 
std::vector< Stringsubsections_
 Container for registered subsections. This member should be filled in the constructor of derived classes! More...
 
String error_name_
 Name that is displayed in error messages during the parameter checking. More...
 
bool check_defaults_
 If this member is set to false no checking if parameters in done;. More...
 
bool warn_empty_defaults_
 If this member is set to false no warning is emitted when defaults are empty;. More...
 

Private Member Functions

 MorphologicalFilter (const MorphologicalFilter &source)
 copy constructor not implemented More...
 

Additional Inherited Members

- Public Types inherited from ProgressLogger
enum  LogType { CMD , GUI , NONE }
 Possible log types. More...
 
- Static Public Member Functions inherited from DefaultParamHandler
static void writeParametersToMetaValues (const Param &write_this, MetaInfoInterface &write_here, const String &key_prefix="")
 Writes all parameters to meta values. More...
 
- Static Protected Member Functions inherited from ProgressLogger
static String logTypeToFactoryName_ (LogType type)
 Return the name of the factory product used for this log type. More...
 
- Static Protected Attributes inherited from ProgressLogger
static int recursion_depth_
 

Detailed Description

This class implements baseline filtering operations using methods from mathematical morphology.

The fundamental operations are erosion and dilation. These are defined with respect to a structuring element. In our case, this is just a straight line and the definitions can be given as follows:

Assume that the input is \(x_0, x_1, x_2, ...\). Then the erosion of \(x\) contains the minima of a sliding window of size struc_size around \( i \), i.e.

\[ \mathrm{erosion}_i = \min\{x_{i-\mathrm{struc\_size}/2}, \ldots, x_{i+\mathrm{struc\_size}/2}\} \]

. The dilation of \(x\) contains the maxima of a sliding window of size struc_size around \( i \), i.e.

\[ \mathrm{dilation}_i = \max\{x_{i-\mathrm{struc\_size}/2}, \ldots, x_{i+\mathrm{struc\_size}/2}\} \]

.

For morphological baseline filtering the tophat method is used. The tophat transform is defined as signal minus opening, where the opening is the dilation of the erosion of the signal.

Several other morphological operations are implemented as well. See the image below and the documentation for further explanation.

Note
The class MorphologicalFilter is designed for uniformly spaced profile data.
The data must be sorted according to ascending m/z!
Parameters of this class are:

NameTypeDefaultRestrictionsDescription
struc_elem_length float3.0  Length of the structuring element. This should be wider than the expected peak width.
struc_elem_unit stringThomson Thomson, DataPointsThe unit of the 'struct_elem_length'.
method stringtophat identity, erosion, dilation, opening, closing, gradient, tophat, bothat, erosion_simple, dilation_simpleMethod to use, the default is 'tophat'. Do not change this unless you know what you are doing. The other methods may be useful for tuning the parameters, see the class documentation of MorpthologicalFilter.

Note:
  • If a section name is documented, the documentation is displayed as tooltip.
  • Advanced parameter names are italic.

Constructor & Destructor Documentation

◆ MorphologicalFilter() [1/2]

MorphologicalFilter ( )
inline

Constructor.

◆ ~MorphologicalFilter()

~MorphologicalFilter ( )
inlineoverride

Destructor.

◆ MorphologicalFilter() [2/2]

MorphologicalFilter ( const MorphologicalFilter source)
private

copy constructor not implemented

Member Function Documentation

◆ applyDilation_()

void applyDilation_ ( Int  struc_size,
InputIterator  input,
InputIterator  input_end,
OutputIterator  output 
)
inlineprotected

Applies dilation. This implementation uses van Herk's method. Only 3 min/max comparisons are required per data point, independent of struc_size.

◆ applyDilationSimple_()

void applyDilationSimple_ ( Int  struc_size,
InputIterator  input_begin,
InputIterator  input_end,
OutputIterator  output_begin 
)
inlineprotected

Applies dilation. Simple implementation, possibly faster if struc_size is very small, and used in some special cases.

◆ applyErosion_()

void applyErosion_ ( Int  struc_size,
InputIterator  input,
InputIterator  input_end,
OutputIterator  output 
)
inlineprotected

Applies erosion. This implementation uses van Herk's method. Only 3 min/max comparisons are required per data point, independent of struc_size.

◆ applyErosionSimple_()

void applyErosionSimple_ ( Int  struc_size,
InputIterator  input_begin,
InputIterator  input_end,
OutputIterator  output_begin 
)
inlineprotected

Applies erosion. Simple implementation, possibly faster if struc_size is very small, and used in some special cases.

◆ filter()

void filter ( MSSpectrum spectrum)
inline

Applies the morphological filtering operation to an MSSpectrum.

If the size of the structuring element is given in 'Thomson', the number of data points for the structuring element is computed as follows:

  • The data points are assumed to be uniformly spaced. We compute the average spacing from the position of the first and the last peak and the total number of peaks in the input range.
  • The number of data points in the structuring element is computed from struc_size and the average spacing, and rounded up to an odd number.

References OpenMS::Internal::intensityIteratorWrapper(), OpenMS::Math::isOdd(), SpectrumSettings::PROFILE, and SpectrumSettings::setType().

◆ filterExperiment()

void filterExperiment ( PeakMap exp)
inline

Applies the morphological filtering operation to an MSExperiment.

The size of the structuring element is computed for each spectrum individually, if it is given in 'Thomson'. See the filtering method for MSSpectrum for details.

References MSExperiment::size().

◆ filterRange()

void filterRange ( InputIterator  input_begin,
InputIterator  input_end,
OutputIterator  output_begin 
)
inline

Applies the morphological filtering operation to an iterator range.

Input and output range must be valid, i.e. allocated before. InputIterator must be a random access iterator type.

Parameters
input_beginthe begin of the input range
input_endthe end of the input range
output_beginthe begin of the output range
Exceptions
Exception::IllegalArgumentThe given method is not one of the values defined in the method parameter.

Member Data Documentation

◆ struct_size_in_datapoints_

UInt struct_size_in_datapoints_
protected

Member for struct size in data points.