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 222 223 224 225 226
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkHessianToObjectnessMeasureImageFilter.txx,v $
Language: C++
Date: $Date: 2009-05-11 07:50:26 $
Version: $Revision: 1.5 $
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 __itkHessianToObjectnessMeasureImageFilter_txx
#define __itkHessianToObjectnessMeasureImageFilter_txx
#include "itkHessianToObjectnessMeasureImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkProgressAccumulator.h"
#include "itkSymmetricEigenAnalysis.h"
#include "vnl/vnl_math.h"
namespace itk
{
/**
* Constructor
*/
template < typename TInputImage, typename TOutputImage >
HessianToObjectnessMeasureImageFilter< TInputImage, TOutputImage>
::HessianToObjectnessMeasureImageFilter()
{
m_Alpha = 0.5;
m_Beta = 0.5;
m_Gamma = 5.0;
m_ScaleObjectnessMeasure = true;
// by default extract bright lines (equivalent to vesselness)
m_ObjectDimension = 1;
m_BrightObject = true;
}
template < typename TInputImage, typename TOutputImage >
void
HessianToObjectnessMeasureImageFilter< TInputImage, TOutputImage>
::BeforeThreadedGenerateData( void )
{
if (m_ObjectDimension >= ImageDimension)
{
itkExceptionMacro( "ObjectDimension must be lower than ImageDimension." );
}
}
template < typename TInputImage, typename TOutputImage >
void
HessianToObjectnessMeasureImageFilter< TInputImage, TOutputImage>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId)
{
typename OutputImageType::Pointer output = this->GetOutput();
typename InputImageType::ConstPointer input = this->GetInput();
// support progress methods/callbacks
ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels(), 1000 / this->GetNumberOfThreads() );
// calculator for computation of the eigen values
typedef SymmetricEigenAnalysis< InputPixelType, EigenValueArrayType > CalculatorType;
CalculatorType eigenCalculator( ImageDimension );
// walk the region of eigen values and get the objectness measure
ImageRegionConstIterator<InputImageType> it(input, outputRegionForThread);
ImageRegionIterator<OutputImageType> oit(output, outputRegionForThread );
oit.GoToBegin();
it.GoToBegin();
while (!it.IsAtEnd())
{
// compute eigen values
EigenValueArrayType eigenValues;
eigenCalculator.ComputeEigenValues( it.Get(), eigenValues );
// Sort the eigenvalues by magnitude but retain their sign
EigenValueArrayType sortedEigenValues = eigenValues;
bool done = false;
while (!done)
{
done = true;
for (unsigned int i=0; i<ImageDimension-1; i++)
{
if (vnl_math_abs(sortedEigenValues[i]) > vnl_math_abs(sortedEigenValues[i+1]))
{
std::swap( sortedEigenValues[i], sortedEigenValues[i+1] );
done = false;
}
}
}
// check whether eigenvalues have the right sign
bool signConstraintsSatisfied = true;
for (unsigned int i=m_ObjectDimension; i<ImageDimension; i++)
{
if ((m_BrightObject && sortedEigenValues[i] > 0.0) ||
(!m_BrightObject && sortedEigenValues[i] < 0.0) )
{
signConstraintsSatisfied = false;
break;
}
}
if (!signConstraintsSatisfied)
{
oit.Set(NumericTraits< OutputPixelType >::Zero);
++it;
++oit;
progress.CompletedPixel();
continue;
}
EigenValueArrayType sortedAbsEigenValues;
for (unsigned int i=0; i<ImageDimension; i++)
{
sortedAbsEigenValues[i] = vnl_math_abs(sortedEigenValues[i]);
}
// initialize the objectness measure
double objectnessMeasure = 1.0;
// compute objectness from eigenvalue ratios and second-order structureness
if (m_ObjectDimension < ImageDimension-1)
{
double rA = sortedAbsEigenValues[m_ObjectDimension];
double rADenominatorBase = 1.0;
for (unsigned int j=m_ObjectDimension+1; j<ImageDimension; j++)
{
rADenominatorBase *= sortedAbsEigenValues[j];
}
if (vcl_fabs(rADenominatorBase) > 0.0)
{
if ( vcl_fabs( m_Alpha ) > 0.0 )
{
rA /= vcl_pow(rADenominatorBase, 1.0 / (ImageDimension-m_ObjectDimension-1));
objectnessMeasure *= 1.0 - vcl_exp(- 0.5 * vnl_math_sqr(rA) / vnl_math_sqr(m_Alpha));
}
}
else
{
objectnessMeasure = 0.0;
}
}
if (m_ObjectDimension > 0)
{
double rB = sortedAbsEigenValues[m_ObjectDimension-1];
double rBDenominatorBase = 1.0;
for (unsigned int j=m_ObjectDimension; j<ImageDimension; j++)
{
rBDenominatorBase *= sortedAbsEigenValues[j];
}
if (vcl_fabs(rBDenominatorBase) > 0.0 && vcl_fabs( m_Beta ) > 0.0 )
{
rB /= vcl_pow(rBDenominatorBase, 1.0 / (ImageDimension-m_ObjectDimension));
objectnessMeasure *= vcl_exp(- 0.5 * vnl_math_sqr(rB) / vnl_math_sqr(m_Beta));
}
else
{
objectnessMeasure = 0.0;
}
}
if ( vcl_fabs( m_Gamma ) > 0.0 )
{
double frobeniusNormSquared = 0.0;
for (unsigned int i=0; i<ImageDimension; i++)
{
frobeniusNormSquared += vnl_math_sqr(sortedAbsEigenValues[i]);
}
objectnessMeasure *= 1.0 - vcl_exp(- 0.5 * frobeniusNormSquared / vnl_math_sqr(m_Gamma));
}
// in case, scale by largest absolute eigenvalue
if (m_ScaleObjectnessMeasure)
{
objectnessMeasure *= sortedAbsEigenValues[ImageDimension-1];
}
oit.Set( static_cast< OutputPixelType >(objectnessMeasure));
++it;
++oit;
progress.CompletedPixel();
}
}
template < typename TInputImage, typename TOutputImage >
void
HessianToObjectnessMeasureImageFilter< TInputImage, TOutputImage>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Alpha: " << m_Alpha << std::endl;
os << indent << "Beta: " << m_Beta << std::endl;
os << indent << "Gamma: " << m_Gamma << std::endl;
os << indent << "ScaleObjectnessMeasure: " << m_ScaleObjectnessMeasure << std::endl;
os << indent << "ObjectDimension: " << m_ObjectDimension << std::endl;
os << indent << "BrightObject: " << m_BrightObject << std::endl;
}
} // end namespace itk
#endif
|