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}};
150 m_DirectionFlags = flags;
169 std::cout <<
"NeighborhoodCooccurenceMatrix" << std::endl;
172 inline OutputVectorType
operator()(
const TNeighborhoodType & it)
const 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;
184 OutputVectorType nullRes; nullRes.fill(0);
189 MeasurementVectorType minBorder;
190 MeasurementVectorType maxBorder;
196 minBorder.SetSize(2);
199 maxBorder.SetSize(2);
202 MeasurementVectorType cooccur;
205 OutputVectorType output_vector;
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 ++){
216 if(! (dir_it->first & m_DirectionFlags))
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
static const unsigned int OutputCount
OutputVectorType operator()(const TNeighborhoodType &it) const
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)
static std::map< OffsetDirection, OffsetType > CreateStdOffsets()
TNeighborhoodType::OffsetType OffsetType
itk::Statistics::Histogram< double, itk::Statistics::DenseFrequencyContainer2 > HistogramType