[Insight-users] bandpass filter in ITK
Dan Mueller
dan.muel at gmail.com
Mon Jan 23 17:18:59 EST 2012
Hi,
Do you mean intensity bandpass? i.e. apply a gain to pixel intensities
within a certain band, and reduce the pixel intensity outside of this
band?
If so, the following code may help:
itkSmoothBandPassImageFilter.h:
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSmoothBandPassImageFilter.h,v $
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
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.
=========================================================================*/
#ifndef __itkSmoothBandPassImageFilter_h
#define __itkSmoothBandPassImageFilter_h
#include "itkUnaryFunctorImageFilter.h"
#include "vnl/vnl_math.h"
namespace itk
{
/** Helper function implementing the smooth band pass operation. */
namespace Function {
template<class TInput, class TOutput>
class SmoothBandPass
{
public:
SmoothBandPass() { m_Center = m_Width = m_Smoothness = 0.0; }
~SmoothBandPass() {}
bool operator!=( const SmoothBandPass & ) const
{
return false;
}
bool operator==( const SmoothBandPass & other ) const
{
return !(*this != other);
}
double GetCenter() const
{
return m_Center;
}
void SetCenter(const double center)
{
m_Center = center;
UpdateParameters();
}
double GetWidth() const
{
return m_Width;
}
void SetWidth(const double width)
{
m_Width = width;
UpdateParameters();
}
double GetSmoothness() const
{
return m_Smoothness;
}
void SetSmoothness(const double smoothness)
{
m_Smoothness = smoothness;
UpdateParameters();
}
inline TOutput operator()( const TInput & input ) const
{
typedef NumericTraits<TOutput>::RealType RealType;
RealType output = vcl_tanh((input-m_Lower)*m_Scaling) +
vcl_tanh((m_Upper-input)*m_Scaling);
output /= 2.0;
return static_cast<TOutput>(output);
}
private:
void UpdateParameters()
{
m_Lower = m_Center - m_Width/2.0;
m_Upper = m_Lower + m_Width;
double e = vcl_pow(10.0, -1.0*m_Smoothness);
m_Scaling = vcl_log((2-e)/e) / (m_Upper-m_Lower);
}
double m_Center;
double m_Width;
double m_Smoothness;
double m_Lower;
double m_Upper;
double m_Scaling;
};
}
/** \class SmoothBandPassImageFilter
* \brief Applies a smooth band pass filtering operation.
*
* \ingroup IntensityImageFilters Multithreaded
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT SmoothBandPassImageFilter :
public UnaryFunctorImageFilter<TInputImage,TOutputImage,
Function::SmoothBandPass<
typename TInputImage::PixelType,
typename TOutputImage::PixelType> >
{
public:
/** Standard class typedefs. */
typedef SmoothBandPassImageFilter Self;
typedef UnaryFunctorImageFilter<
TInputImage,TOutputImage,
Function::SmoothBandPass< typename TInputImage::PixelType,
typename TOutputImage::PixelType> >
Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Runtime information support. */
itkTypeMacro(SmoothBandPassImageFilter,
UnaryFunctorImageFilter);
typedef typename TInputImage::PixelType InputPixelType;
typedef typename TOutputImage::PixelType OutputPixelType;
/** Get/set band pass window center. */
virtual double GetCenter() const
{
return this->GetFunctor().GetCenter();
}
virtual void SetCenter(const double center)
{
if( center != this->GetFunctor().GetCenter() )
{
this->GetFunctor().SetCenter( center );
this->Modified();
}
}
/** Get/set band pass window width. */
virtual double GetWidth() const
{
return this->GetFunctor().GetWidth();
}
virtual void SetWidth(const double width)
{
if( width != this->GetFunctor().GetWidth() )
{
this->GetFunctor().SetWidth( width );
this->Modified();
}
}
/** Get/set band pass window smoothness.
* Clamped to the range [0,1000]. A good value is 3.0.
*/
virtual double GetSmoothness() const
{
return this->GetFunctor().GetSmoothness();
}
virtual void SetSmoothness(const double smoothness)
{
double clamped = (smoothness<0.0 ? 0.0 : (smoothness>1000.0 ?
1000.0 : smoothness));
if( clamped != this->GetFunctor().GetSmoothness() )
{
this->GetFunctor().SetSmoothness( clamped );
this->Modified();
}
}
#ifdef ITK_USE_CONCEPT_CHECKING
/** Begin concept checking */
itkConceptMacro(InputConvertibleToOutputCheck,
(Concept::Convertible<InputPixelType, OutputPixelType>));
/** End concept checking */
#endif
protected:
SmoothBandPassImageFilter() {}
virtual ~SmoothBandPassImageFilter() {}
private:
SmoothBandPassImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace itk
#endif
On 24 January 2012 01:24, barbababa <tonimuusimaki at gmail.com> wrote:
>
> Dear List,
>
> I am trying to highlight some spherical particles with certain size from a
> background in a 3D image and i figured that some bandpass filtering with
> correct limits should do the work.
> Is there some bandpass filtering filters implemented in ITK at present?
>
>
> Sir thanks alot!
More information about the Insight-users
mailing list