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
|
/*=========================================================================
Program: VMTK
Module: $RCSfile: itkFWHMFeatureImageFilter.txx,v $
Language: C++
Date: $Date: 2005/03/04 11:14:37 $
Version: $Revision: 1.2 $
Copyright (c) Luca Antiga, David Steinman. All rights reserved.
See LICENCE file for details.
Portions of this code are covered under the VTK copyright.
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
for details.
Portions of this code are covered under the ITK copyright.
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 _itkFWHMFeatureImageFilter_txx
#define _itkFWHMFeatureImageFilter_txx
#include "itkFWHMFeatureImageFilter.h"
#include "itkGrayscaleDilateImageFilter.h"
#include "itkSigmoidImageFilter.h"
namespace itk
{
template <typename TInputImage, typename TOutputImage>
FWHMFeatureImageFilter<TInputImage,TOutputImage>
::FWHMFeatureImageFilter()
: m_UseImageSpacing( true )
{
m_Radius.Fill(1);
m_BackgroundValue = NumericTraits<InputPixelType>::Zero;
}
template< typename TInputImage, typename TOutputImage >
void
FWHMFeatureImageFilter< TInputImage, TOutputImage >
::GenerateData()
{
this->AllocateOutputs();
StructuringElementRadiusType radius = m_Radius;
typedef itk::GrayscaleDilateImageFilter<InputImageType,InputImageType,StructuringElementType> GrayscaleDilateFilterType;
typename InputImageType::ConstPointer inputImage = this->GetInput();
StructuringElementType dilateStructuringElement;
dilateStructuringElement.SetRadius(radius);
dilateStructuringElement.CreateStructuringElement();
typename GrayscaleDilateFilterType::Pointer grayscaleDilateFilter = GrayscaleDilateFilterType::New();
grayscaleDilateFilter->SetInput(inputImage);
grayscaleDilateFilter->SetKernel(dilateStructuringElement);
grayscaleDilateFilter->Update();
typename OutputImageType::Pointer outputImage = this->GetOutput();
// build output image as sigmoid-filtered difference between pixel and half-maximum
// using Sigmoid functor
itk::Functor::Sigmoid<InputPixelType,OutputPixelType> sigmoid;
sigmoid.SetAlpha(1.0/6.0);
sigmoid.SetBeta(0.0);
sigmoid.SetOutputMinimum(-1.0);
sigmoid.SetOutputMaximum(1.0);
ImageRegionConstIterator<InputImageType> inputIt(inputImage, inputImage->GetBufferedRegion());
ImageRegionConstIterator<InputImageType> dilateIt(grayscaleDilateFilter->GetOutput(), grayscaleDilateFilter->GetOutput()->GetBufferedRegion());
ImageRegionIterator<OutputImageType> outputIt(outputImage, outputImage->GetBufferedRegion());
inputIt.GoToBegin();
dilateIt.GoToBegin();
outputIt.GoToBegin();
while( !inputIt.IsAtEnd() || !dilateIt.IsAtEnd() || !outputIt.IsAtEnd())
{
InputPixelType inputPixel = inputIt.Get();
InputPixelType inputPixelToBackgroundValue = inputPixel - m_BackgroundValue;
InputPixelType dilatePixel = dilateIt.Get();
InputPixelType halfMaximumToBackgroundValue = (dilatePixel - m_BackgroundValue) / 2.0;
InputPixelType featureValue = sigmoid(inputPixelToBackgroundValue-halfMaximumToBackgroundValue);
outputIt.Set(featureValue);
++inputIt;
++dilateIt;
++outputIt;
}
}
template <typename TInputImage, typename TOutputImage>
void
FWHMFeatureImageFilter<TInputImage, TOutputImage>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "UseImageSpacing = " << m_UseImageSpacing << std::endl;
os << indent << "Radius = " << m_Radius << std::endl;
os << indent << "BackgroundValue = " << m_BackgroundValue << std::endl;
}
} // end namespace itk
#endif
|