13 #ifndef itkCooccurenceMatrixFeatureFunctor_h
14 #define itkCooccurenceMatrixFeatureFunctor_h
16 #include "itkConstNeighborhoodIterator.h"
18 #include <itkHistogramToTextureFeaturesFilter.h>
19 #include <itkHistogram.h>
36 template<
typename TNeighborhoodType,
typename TPixelOutputType>
42 typedef itk::Statistics::Histogram< double, itk::Statistics::DenseFrequencyContainer2 >
HistogramType;
43 typedef typename TNeighborhoodType::OffsetType
OffsetType;
44 typedef typename HistogramType::SizeType
SizeType;
58 static const char *
const FeatureNames[] = {
"ENERGY",
"ENTROPY",
"CORRELATION",
"INERTIA",
"CLUSTERSHADE",
"CLUSTERPROMINENCE",
"HARALICKCORRELATION",
"INVERSEDIFFERENCEMOMENT"};
59 return FeatureNames[f];
82 std::map<OffsetDirection,OffsetType> offsetMap;
85 itk::Offset<3> off = {{1,0,0}};
89 itk::Offset<3> off = {{1,1,0}};
93 itk::Offset<3> off = {{0,1,0}};
97 itk::Offset<3> off = {{-1,1,0}};
101 itk::Offset<3> off = {{1,0,1}};
105 itk::Offset<3> off = {{1,1,1}};
109 itk::Offset<3> off = {{0,1,1}};
113 itk::Offset<3> off = {{-1,1,1}};
117 itk::Offset<3> off = {{1,0,-1}};
121 itk::Offset<3> off = {{1,1,-1}};
125 itk::Offset<3> off = {{0,1,-1}};
129 itk::Offset<3> off = {{-1,1,-1}};
133 itk::Offset<3> off = {{0,0,1}};
169 std::cout <<
"NeighborhoodCooccurenceMatrix" << std::endl;
174 double min = std::numeric_limits<double>::max();
175 double max = std::numeric_limits<double>::min();
176 for (
unsigned int i = 0; i < it.Size(); ++i)
178 double value = it.GetPixel(i);
179 max = (value > max) ? value : max;
180 min = (value < min) ? value : min;
196 minBorder.SetSize(2);
199 maxBorder.SetSize(2);
206 output_vector.fill(0);
208 double div_num_dirs = 0;
213 for(
typename std::map<OffsetDirection,OffsetType>::const_iterator dir_it =
m_offsetMap.begin(),
214 end =
m_offsetMap.end(); dir_it != end; dir_it ++){
221 HistogramType::Pointer histogram = HistogramType::New();
222 histogram->SetMeasurementVectorSize(2);
223 histogram->Initialize(size, minBorder, maxBorder);
225 for (
unsigned int i = 0; i < it.Size(); ++i)
229 g1 = it.GetOffset(i);
230 g2 = g1 + dir_it->second;
232 cooccur[0] = it.GetPixel(i);
233 cooccur[1] = it.GetImagePointer()->GetPixel(it.GetIndex(i)+dir_it->second);
235 histogram->IncreaseFrequencyOfMeasurement(cooccur, 1);
238 histogram->IncreaseFrequencyOfMeasurement(cooccur, 1);
243 HistoToFeatureFilter::Pointer filter = HistoToFeatureFilter::New();
244 filter->SetInput(histogram);
247 output_vector[
ENERGY] += filter->GetEnergy();
248 output_vector[
ENTROPY] += filter->GetEntropy();
249 output_vector[
CORRELATION] += filter->GetCorrelation();
250 output_vector[
INERTIA] += filter->GetInertia();
251 output_vector[
CLUSTERSHADE] += filter->GetClusterShade();
259 return output_vector;
267 #endif // itkNeighborhoodFunctors_h