1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/*=========================================================================
Program: ITK-SNAP
Module: $RCSfile: EdgePreprocessingImageFilter.h,v $
Language: C++
Date: $Date: 2009/01/24 01:50:21 $
Version: $Revision: 1.4 $
Copyright (c) 2007 Paul A. Yushkevich
This file is part of ITK-SNAP
ITK-SNAP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-----
Copyright (c) 2003 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 __EdgePreprocessingFilter_h_
#define __EdgePreprocessingFilter_h_
#include "itkCommand.h"
#include "itkImageToImageFilter.h"
#include "EdgePreprocessingSettings.h"
#include "GPUSettings.h"
#ifdef SNAP_USE_GPU
#include "CPUImageToGPUImageFilter.h"
#include <itkGPUDiscreteGaussianImageFilter.h>
#endif
namespace itk {
template <class TIn, class TOut> class DiscreteGaussianImageFilter;
template <class TIn, class TOut> class GradientMagnitudeImageFilter;
template <class TIn, class TOut, class Fun> class UnaryFunctorImageFilter;
template <class TIn, class TOut> class StreamingImageFilter;
template <class TIn, class TOut> class CastImageFilter;
}
/**
* The g() function that remaps the gradient magnitude image to the
* range 0 to 1.
*/
template<class TInput>
class EdgeRemappingFunctor
{
public:
typedef EdgeRemappingFunctor<TInput> Self;
void SetParameters(float intensityMin, float intensityMax,
float exponent, float kappa)
{
m_KappaFactor = 1.0f / kappa;
m_Exponent = exponent;
m_IntensityBase = intensityMin;
m_IntensityScale = 1.0f / (intensityMax - intensityMin);
}
// This operator maps the input value into the range of short integers
inline short operator()(const TInput &x)
{
float xNorm = (static_cast<float>(x)-m_IntensityBase)*m_IntensityScale;
float y = 1.0 / (1.0 + pow(xNorm * m_KappaFactor,m_Exponent));
return static_cast<short> (y * 0x7fff);
}
bool operator ==(const Self &z)
{
return
m_KappaFactor == z.m_KappaFactor &&
m_IntensityBase == z.m_IntensityBase &&
m_IntensityScale == z.m_IntensityScale &&
m_Exponent == z.m_Exponent;
}
bool operator !=(const Self &z)
{ return !(*this == z); }
private:
float m_KappaFactor;
float m_IntensityBase;
float m_IntensityScale;
float m_Exponent;
};
/**
* \class EdgePreprocessingImageFilter
* \brief A filter used for edge preprocessing of images in the IRIS application.
*
* This functor implements a Gaussian blur, followed by a gradient magnitude
* operator, followed by a 'contrast enhancement' intensity remapping filter.
*/
template <typename TInputImage,typename TOutputImage>
class EdgePreprocessingImageFilter:
public itk::ImageToImageFilter<TInputImage,TOutputImage>
{
public:
/** Standard class typedefs. */
typedef EdgePreprocessingImageFilter Self;
typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Pixel Type of the input image */
typedef TInputImage InputImageType;
typedef typename InputImageType::PixelType InputPixelType;
typedef itk::SmartPointer<InputImageType> InputImagePointer;
/** Pixel Type of the output image */
typedef TOutputImage OutputImageType;
typedef itk::SmartPointer<OutputImageType> OutputImagePointer;
typedef typename Superclass::OutputImageRegionType
OutputImageRegionType;
/** Type used for internal calculations */
typedef float RealType;
typedef itk::Image<RealType,3> InternalImageType;
typedef itk::SmartPointer<InternalImageType> InternalImagePointer;
#ifdef SNAP_USE_GPU
typedef typename itk::GPUTraits<InternalImageType>::Type
GPUInternalImageType;
typedef itk::SmartPointer<GPUInternalImageType>
GPUInternalImagePointer;
#endif
/** Functor type used for thresholding */
typedef EdgeRemappingFunctor<RealType> FunctorType;
/** Method for creation through the object factory. */
itkNewMacro(Self)
/** Image dimension. */
itkStaticConstMacro(ImageDimension, unsigned int,
TInputImage::ImageDimension);
/** Assign new edge processing settings */
void SetParameters(EdgePreprocessingSettings *parameters);
/** Set the maximum possible value of the gradient magnitude of the input
image. This should be computed by applying a gradient magnitude filter
to the input image. Must be provided for the filter to work. */
itkSetMacro(InputImageMaximumGradientMagnitude, double)
/** Get the parameters pointer */
EdgePreprocessingSettings *GetParameters();
protected:
EdgePreprocessingImageFilter();
virtual ~EdgePreprocessingImageFilter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** Generate Data */
void GenerateData();
/**
* This method maps an input region to an output region. It's necessary to
* reflect the way this filter pads the requested region
*/
void GenerateInputRequestedRegion();
private:
double m_InputImageMaximumGradientMagnitude;
typedef itk::CastImageFilter<InputImageType, InternalImageType> CastFilter;
typedef itk::DiscreteGaussianImageFilter<InternalImageType,
InternalImageType> BlurFilter;
#ifdef SNAP_USE_GPU
typedef CPUImageToGPUImageFilter<GPUInternalImageType> GPUImageSource;
typedef itk::GPUDiscreteGaussianImageFilter<GPUInternalImageType,
GPUInternalImageType>
GPUBlurFilter;
#endif
typedef itk::GradientMagnitudeImageFilter<InternalImageType,
InternalImageType> GradMagFilter;
typedef itk::UnaryFunctorImageFilter<InternalImageType,
OutputImageType,
FunctorType> RemapFilter;
SmartPtr<CastFilter> m_CastFilter;
SmartPtr<BlurFilter> m_BlurFilter;
SmartPtr<GradMagFilter> m_GradMagFilter;
SmartPtr<RemapFilter> m_RemapFilter;
#ifdef SNAP_USE_GPU
SmartPtr<GPUImageSource> m_GPUImageSource;
SmartPtr<GPUBlurFilter> m_GPUBlurFilter;
#endif
};
#ifndef ITK_MANUAL_INSTANTIATION
#include "EdgePreprocessingImageFilter.txx"
#endif
#endif // __EdgePreprocessingFilter_h_
|