1 #ifndef itkCooccurenceMatrixFeatureFunctor_h
2 #define itkCooccurenceMatrixFeatureFunctor_h
4 #include "itkConstNeighborhoodIterator.h"
6 #include <itkHistogramToTextureFeaturesFilter.h>
7 #include <itkHistogram.h>
24 template<
typename TNeighborhoodType,
typename TPixelOutputType>
30 typedef itk::Statistics::Histogram< double, itk::Statistics::DenseFrequencyContainer2 >
HistogramType;
31 typedef typename TNeighborhoodType::OffsetType
OffsetType;
32 typedef typename HistogramType::SizeType
SizeType;
46 static const char *
const FeatureNames[] = {
"ENERGY",
"ENTROPY",
"CORRELATION",
"INERTIA",
"CLUSTERSHADE",
"CLUSTERPROMINENCE",
"HARALICKCORRELATION",
"INVERSEDIFFERENCEMOMENT"};
47 return FeatureNames[f];
70 std::map<OffsetDirection,OffsetType> offsetMap;
73 itk::Offset<3> off = {{1,0,0}};
77 itk::Offset<3> off = {{1,1,0}};
81 itk::Offset<3> off = {{0,1,0}};
85 itk::Offset<3> off = {{-1,1,0}};
89 itk::Offset<3> off = {{1,0,1}};
93 itk::Offset<3> off = {{1,1,1}};
97 itk::Offset<3> off = {{0,1,1}};
101 itk::Offset<3> off = {{-1,1,1}};
105 itk::Offset<3> off = {{1,0,-1}};
109 itk::Offset<3> off = {{1,1,-1}};
113 itk::Offset<3> off = {{0,1,-1}};
117 itk::Offset<3> off = {{-1,1,-1}};
121 itk::Offset<3> off = {{0,0,1}};
138 m_DirectionFlags = flags;
157 std::cout <<
"NeighborhoodCooccurenceMatrix" << std::endl;
160 inline OutputVectorType
operator()(
const TNeighborhoodType & it)
const
164 for (
unsigned int i = 0; i < it.Size(); ++i)
166 double value = it.GetPixel(i);
167 max = (value >
max) ? value : max;
168 min = (value <
min) ? value : min;
172 OutputVectorType nullRes; nullRes.fill(0);
177 MeasurementVectorType minBorder;
178 MeasurementVectorType maxBorder;
184 minBorder.SetSize(2);
187 maxBorder.SetSize(2);
190 MeasurementVectorType cooccur;
193 OutputVectorType output_vector;
194 output_vector.fill(0);
196 double div_num_dirs = 0;
201 for(
typename std::map<OffsetDirection,OffsetType>::const_iterator dir_it = m_offsetMap.begin(),
202 end = m_offsetMap.end(); dir_it != end; dir_it ++){
204 if(! (dir_it->first & m_DirectionFlags))
210 histogram->SetMeasurementVectorSize(2);
211 histogram->Initialize(size, minBorder, maxBorder);
213 for (
unsigned int i = 0; i < it.Size(); ++i)
217 g1 = it.GetOffset(i);
218 g2 = g1 + dir_it->second;
220 cooccur[0] = it.GetPixel(i);
221 cooccur[1] = it.GetImagePointer()->GetPixel(it.GetIndex(i)+dir_it->second);
223 histogram->IncreaseFrequencyOfMeasurement(cooccur, 1);
226 histogram->IncreaseFrequencyOfMeasurement(cooccur, 1);
232 filter->SetInput(histogram);
235 output_vector[
ENERGY] += filter->GetEnergy();
236 output_vector[
ENTROPY] += filter->GetEntropy();
237 output_vector[
CORRELATION] += filter->GetCorrelation();
238 output_vector[
INERTIA] += filter->GetInertia();
239 output_vector[
CLUSTERSHADE] += filter->GetClusterShade();
247 return output_vector;
255 #endif // itkNeighborhoodFunctors_h
itk::SmartPointer< Self > Pointer
static const unsigned int OutputCount
void DirectionFlags(OffsetDirection flags)
itk::Statistics::HistogramToTextureFeaturesFilter< HistogramType > HistoToFeatureFilter
static const char * GetFeatureName(unsigned int f)
HistogramType::MeasurementVectorType MeasurementVectorType
NeighborhoodCooccurenceMatrix()
vnl_vector_fixed< TPixelOutputType, OutputCount > OutputVectorType
std::map< OffsetDirection, OffsetType > m_offsetMap
void DirectionFlags(int flags)
void SetLevels(unsigned int lvl)
Functor for texture feature calculation based on the Cooccurence matrix.
HistogramType::SizeType SizeType
TNeighborhoodType NeighborhoodType
static void swap(T &x, T &y)
OutputVectorType operator()(const TNeighborhoodType &it) const
static std::map< OffsetDirection, OffsetType > CreateStdOffsets()
TNeighborhoodType::OffsetType OffsetType
itk::Statistics::Histogram< double, itk::Statistics::DenseFrequencyContainer2 > HistogramType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.