/*========================================================================= Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkHistogramToRunLengthFeaturesFilter.txx,v $ Language: C++ Date: $Date: 2008/10/18 00:22:58 $ Version: $Revision: 1.1.1.1 $ 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 _itkHistogramToRunLengthFeaturesFilter_txx #define _itkHistogramToRunLengthFeaturesFilter_txx #include "itkHistogramToRunLengthFeaturesFilter.h" #include "itkNumericTraits.h" #include "vnl/vnl_math.h" namespace itk { namespace Statistics { //constructor template HistogramToRunLengthFeaturesFilter ::HistogramToRunLengthFeaturesFilter() { this->ProcessObject::SetNumberOfRequiredInputs( 1 ); // allocate the data objects for the outputs which are // just decorators real types for( unsigned int i = 0; i < 10; i++ ) { this->ProcessObject::SetNthOutput( i, this->MakeOutput( i ) ); } } template void HistogramToRunLengthFeaturesFilter< THistogram> ::SetInput( const HistogramType *histogram ) { this->ProcessObject::SetNthInput( 0, const_cast( histogram ) ); } template const typename HistogramToRunLengthFeaturesFilter::HistogramType * HistogramToRunLengthFeaturesFilter< THistogram> ::GetInput() const { if ( this->GetNumberOfInputs() < 1 ) { return 0; } return static_cast( this->ProcessObject::GetInput( 0 ) ); } template typename HistogramToRunLengthFeaturesFilter::DataObjectPointer HistogramToRunLengthFeaturesFilter ::MakeOutput( unsigned int itkNotUsed( idx ) ) { return static_cast(MeasurementObjectType::New().GetPointer()); } template void HistogramToRunLengthFeaturesFilter< THistogram>:: GenerateData( void ) { const HistogramType * inputHistogram = this->GetInput(); this->m_TotalNumberOfRuns = static_cast ( inputHistogram->GetTotalFrequency() ); MeasurementType shortRunEmphasis = NumericTraits::Zero; MeasurementType longRunEmphasis = NumericTraits::Zero; MeasurementType greyLevelNonuniformity = NumericTraits::Zero; MeasurementType runLengthNonuniformity = NumericTraits::Zero; MeasurementType lowGreyLevelRunEmphasis = NumericTraits::Zero; MeasurementType highGreyLevelRunEmphasis = NumericTraits::Zero; MeasurementType shortRunLowGreyLevelEmphasis = NumericTraits::Zero; MeasurementType shortRunHighGreyLevelEmphasis = NumericTraits::Zero; MeasurementType longRunLowGreyLevelEmphasis = NumericTraits::Zero; MeasurementType longRunHighGreyLevelEmphasis = NumericTraits::Zero; vnl_vector greyLevelNonuniformityVector( inputHistogram->GetSize()[0], 0.0 ); vnl_vector runLengthNonuniformityVector( inputHistogram->GetSize()[1], 0.0 ); typedef typename HistogramType::ConstIterator HistogramIterator; for ( HistogramIterator hit = inputHistogram->Begin(); hit != inputHistogram->End(); ++hit ) { MeasurementType frequency = hit.GetFrequency(); if ( frequency == 0 ) { continue; } MeasurementVectorType measurement = hit.GetMeasurementVector(); IndexType index = inputHistogram->GetIndex( hit.GetInstanceIdentifier() ); double i2 = static_cast( ( index[0] + 1 ) * ( index[0] + 1 ) ); double j2 = static_cast( ( index[1] + 1 ) * ( index[1] + 1 ) ); // Traditional measures shortRunEmphasis += ( frequency / j2 ); longRunEmphasis += ( frequency * j2 ); greyLevelNonuniformityVector[index[0]] += frequency; runLengthNonuniformityVector[index[1]] += frequency; // measures from Chu et al. lowGreyLevelRunEmphasis += ( frequency / i2 ); highGreyLevelRunEmphasis += ( frequency * i2 ); // measures from Dasarathy and Holder shortRunLowGreyLevelEmphasis += ( frequency / ( i2 * j2 ) ); shortRunHighGreyLevelEmphasis += ( frequency * i2 / j2 ); longRunLowGreyLevelEmphasis += ( frequency * j2 / i2 ); longRunHighGreyLevelEmphasis += ( frequency * i2 * j2 ); } greyLevelNonuniformity = greyLevelNonuniformityVector.squared_magnitude(); runLengthNonuniformity = runLengthNonuniformityVector.squared_magnitude(); // Normalize all measures by the total number of runs shortRunEmphasis /= static_cast( this->m_TotalNumberOfRuns ); longRunEmphasis /= static_cast( this->m_TotalNumberOfRuns ); greyLevelNonuniformity /= static_cast( this->m_TotalNumberOfRuns ); runLengthNonuniformity /= static_cast( this->m_TotalNumberOfRuns ); lowGreyLevelRunEmphasis /= static_cast( this->m_TotalNumberOfRuns ); highGreyLevelRunEmphasis /= static_cast( this->m_TotalNumberOfRuns ); shortRunLowGreyLevelEmphasis /= static_cast( this->m_TotalNumberOfRuns ); shortRunHighGreyLevelEmphasis /= static_cast( this->m_TotalNumberOfRuns ); longRunLowGreyLevelEmphasis /= static_cast( this->m_TotalNumberOfRuns ); longRunHighGreyLevelEmphasis /= static_cast( this->m_TotalNumberOfRuns ); MeasurementObjectType* shortRunEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 0 ) ); shortRunEmphasisOutputObject->Set( shortRunEmphasis ); MeasurementObjectType* longRunEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 1 ) ); longRunEmphasisOutputObject->Set( longRunEmphasis ); MeasurementObjectType* greyLevelNonuniformityOutputObject = static_cast( this->ProcessObject::GetOutput( 2 ) ); greyLevelNonuniformityOutputObject->Set( greyLevelNonuniformity ); MeasurementObjectType* runLengthNonuniformityOutputObject = static_cast( this->ProcessObject::GetOutput( 3 ) ); runLengthNonuniformityOutputObject->Set( runLengthNonuniformity ); MeasurementObjectType* lowGreyLevelRunEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 4 ) ); lowGreyLevelRunEmphasisOutputObject->Set( lowGreyLevelRunEmphasis ); MeasurementObjectType* highGreyLevelRunEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 5 ) ); highGreyLevelRunEmphasisOutputObject->Set( highGreyLevelRunEmphasis ); MeasurementObjectType* shortRunLowGreyLevelEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 6 ) ); shortRunLowGreyLevelEmphasisOutputObject->Set( shortRunLowGreyLevelEmphasis ); MeasurementObjectType* shortRunHighGreyLevelEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 7 ) ); shortRunHighGreyLevelEmphasisOutputObject->Set( shortRunHighGreyLevelEmphasis ); MeasurementObjectType* longRunLowGreyLevelEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 8 ) ); longRunLowGreyLevelEmphasisOutputObject->Set( longRunLowGreyLevelEmphasis ); MeasurementObjectType* longRunHighGreyLevelEmphasisOutputObject = static_cast( this->ProcessObject::GetOutput( 9 ) ); longRunHighGreyLevelEmphasisOutputObject->Set( longRunHighGreyLevelEmphasis ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetShortRunEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 0 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetLongRunEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 1 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetGreyLevelNonuniformityOutput() const { return static_cast( this->ProcessObject::GetOutput( 2 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetRunLengthNonuniformityOutput() const { return static_cast( this->ProcessObject::GetOutput( 3 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetLowGreyLevelRunEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 4 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetHighGreyLevelRunEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 5 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetShortRunLowGreyLevelEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 6 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetShortRunHighGreyLevelEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 7 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetLongRunLowGreyLevelEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 8 ) ); } template const typename HistogramToRunLengthFeaturesFilter::MeasurementObjectType* HistogramToRunLengthFeaturesFilter ::GetLongRunHighGreyLevelEmphasisOutput() const { return static_cast( this->ProcessObject::GetOutput( 9 ) ); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetShortRunEmphasis() const { return this->GetShortRunEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetLongRunEmphasis() const { return this->GetLongRunEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetGreyLevelNonuniformity() const { return this->GetGreyLevelNonuniformityOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetRunLengthNonuniformity() const { return this->GetRunLengthNonuniformityOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetLowGreyLevelRunEmphasis() const { return this->GetLowGreyLevelRunEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetHighGreyLevelRunEmphasis() const { return this->GetHighGreyLevelRunEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetShortRunLowGreyLevelEmphasis() const { return this->GetShortRunLowGreyLevelEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetShortRunHighGreyLevelEmphasis() const { return this->GetShortRunHighGreyLevelEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetLongRunLowGreyLevelEmphasis() const { return this->GetLongRunLowGreyLevelEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter::MeasurementType HistogramToRunLengthFeaturesFilter ::GetLongRunHighGreyLevelEmphasis() const { return this->GetLongRunHighGreyLevelEmphasisOutput()->Get(); } template typename HistogramToRunLengthFeaturesFilter< THistogram>::MeasurementType HistogramToRunLengthFeaturesFilter ::GetFeature( RunLengthFeatureName feature ) { switch( feature ) { case ShortRunEmphasis: return this->GetShortRunEmphasis(); case LongRunEmphasis: return this->GetLongRunEmphasis(); case GreyLevelNonuniformity: return this->GetGreyLevelNonuniformity(); case RunLengthNonuniformity: return this->GetRunLengthNonuniformity(); case LowGreyLevelRunEmphasis: return this->GetLowGreyLevelRunEmphasis(); case HighGreyLevelRunEmphasis: return this->GetHighGreyLevelRunEmphasis(); case ShortRunLowGreyLevelEmphasis: return this->GetShortRunLowGreyLevelEmphasis(); case ShortRunHighGreyLevelEmphasis: return this->GetShortRunHighGreyLevelEmphasis(); case LongRunLowGreyLevelEmphasis: return this->GetLongRunLowGreyLevelEmphasis(); case LongRunHighGreyLevelEmphasis: return this->GetLongRunHighGreyLevelEmphasis(); default: return 0; } } template< class THistogram> void HistogramToRunLengthFeaturesFilter< THistogram>:: PrintSelf(std::ostream& os, Indent indent) const { Superclass::PrintSelf( os,indent ); } } // end of namespace Statistics } // end of namespace itk #endif