File: itkHistogramToTextureFeaturesFilter.h

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (220 lines) | stat: -rw-r--r-- 8,401 bytes parent folder | download | duplicates (2)
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
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkHistogramToTextureFeaturesFilter.h
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  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 __itkHistogramToTextureFeaturesFilter_h
#define __itkHistogramToTextureFeaturesFilter_h

#include "itkHistogram.h"
#include "itkMacro.h"
#include "itkProcessObject.h"
#include "itkSimpleDataObjectDecorator.h"

namespace itk {
namespace Statistics {

/** \class HistogramToTextureFeaturesFilter 
*  \brief This class computes texture feature coefficients from a grey level
* co-occurrence matrix.
*
* This class computes features that summarize image texture, given a grey level
* co-occurrence matrix (generated by a ScalarImageToGreyLevelCooccurrenceMatrixGenerator
* or related class).  
*
* The features calculated are as follows (where \f$ g(i, j) \f$ is the element in
* cell i, j of a a normalized GLCM):
*
* "Energy" \f$ = f_1 = \sum_{i,j}g(i, j)^2 \f$
*
* "Entropy" \f$ = f_2 = -\sum_{i,j}g(i, j) \log_2 g(i, j)\f$, or 0 if \f$g(i, j) = 0\f$
*
* "Correlation" \f$ = f_3 = \sum_{i,j}\frac{(i - \mu)(j - \mu)g(i, j)}{\sigma^2} \f$
*
* "Difference Moment" \f$= f_4 = \sum_{i,j}\frac{1}{1 + (i - j)^2}g(i, j) \f$
*
* "Inertia" \f$ = f_5 = \sum_{i,j}(i - j)^2g(i, j) \f$ (sometimes called "contrast.")
*
* "Cluster Shade" \f$ = f_6 = \sum_{i,j}((i - \mu) + (j - \mu))^3 g(i, j) \f$
*
* "Cluster Prominence" \f$ = f_7 = \sum_{i,j}((i - \mu) + (j - \mu))^4 g(i, j) \f$
*
* "Haralick's Correlation" \f$ = f_8 = \frac{\sum_{i,j}(i, j) g(i, j) -\mu_t^2}{\sigma_t^2} \f$
* where \f$\mu_t\f$ and \f$\sigma_t\f$ are the mean and standard deviation of the row
* (or column, due to symmetry) sums.
*
* Above, \f$ \mu =  \f$ (weighted pixel average) \f$ = \sum_{i,j}i \cdot g(i, j) = 
* \sum_{i,j}j \cdot g(i, j) \f$ (due to matrix summetry), and
*
* \f$ \sigma =  \f$ (weighted pixel variance) \f$ = \sum_{i,j}(i - \mu)^2 \cdot g(i, j) = 
* \sum_{i,j}(j - \mu)^2 \cdot g(i, j)  \f$  (due to matrix summetry)
*
* A good texture feature set to use is the Conners, Trivedi and Harlow set: 
* features 1, 2, 4, 5, 6, and 7. There is some correlation between the various
* features, so using all of them at the same time is not necessarialy a good idea.
*
* NOTA BENE: The input histogram will be forcably normalized!
* This algorithm takes three passes through the input
* histogram if the histogram was already normalized, and four if not.
* 
* Web references:
*
* http://www.cssip.uq.edu.au/meastex/www/algs/algs/algs.html
* http://www.ucalgary.ca/~mhallbey/texture/texture_tutorial.html
*
* Print references:
*
* Haralick, R.M., K. Shanmugam and I. Dinstein. 1973.  Textural Features for 
* Image Classification. IEEE Transactions on Systems, Man and Cybernetics. 
* SMC-3(6):610-620.
*
* Haralick, R.M. 1979. Statistical and Structural Approaches to Texture. 
* Proceedings of the IEEE, 67:786-804.
*
* R.W. Conners and C.A. Harlow. A Theoretical Comaprison of Texture Algorithms. 
* IEEE Transactions on Pattern Analysis and Machine Intelligence,  2:204-222, 1980.
*
* R.W. Conners, M.M. Trivedi, and C.A. Harlow. Segmentation of a High-Resolution
* Urban Scene using Texture  Operators. Computer Vision, Graphics and Image 
* Processing, 25:273-310,  1984.
*
* \sa ScalarImageToGreyLevelCooccurrenceMatrixGenerator
* \sa MaskedScalarImageToGreyLevelCooccurrenceMatrixGenerator
* \sa ScalarImageTextureCalculator
*
* Author: Zachary Pincus */

template < class THistogram >
class ITK_EXPORT HistogramToTextureFeaturesFilter : public ProcessObject
{
public:
  /** Standard typedefs */
  typedef HistogramToTextureFeaturesFilter                Self;
  typedef ProcessObject                                   Superclass;
  typedef SmartPointer<Self>                              Pointer;
  typedef SmartPointer<const Self>                        ConstPointer;
  
  /** Run-time type information (and related methods). */
  itkTypeMacro(HistogramToTextureFeaturesFilter, ProcessObject);
  
  /** standard New() method support */
  itkNewMacro(Self);
  
  typedef THistogram                                      HistogramType;
  typedef typename HistogramType::Pointer                 HistogramPointer;
  typedef typename HistogramType::ConstPointer            HistogramConstPointer;
  typedef typename HistogramType::MeasurementType         MeasurementType;
  typedef typename HistogramType::MeasurementVectorType   MeasurementVectorType;
  typedef typename HistogramType::IndexType               IndexType;
  typedef typename HistogramType::AbsoluteFrequencyType   AbsoluteFrequencyType;
  typedef typename HistogramType::RelativeFrequencyType   RelativeFrequencyType;

  typedef typename HistogramType::TotalAbsoluteFrequencyType   
                                                     TotalAbsoluteFrequencyType;

  typedef typename HistogramType::TotalRelativeFrequencyType   
                                                     TotalRelativeFrequencyType;

  /** Container to hold relative frequencies of the histogram */
  typedef std::vector< RelativeFrequencyType >          RelativeFrequencyContainerType;

  /** Method to Set/Get the input Histogram */
  void SetInput ( const HistogramType * histogram );
  const HistogramType * GetInput() const;
  
  /** Smart Pointer type to a DataObject. */
  typedef DataObject::Pointer                   DataObjectPointer;

  /** Type of DataObjects used for scalar outputs */
  typedef SimpleDataObjectDecorator<MeasurementType>     MeasurementObjectType;

  /** Return energy texture value. */
  MeasurementType GetEnergy() const;
  const MeasurementObjectType* GetEnergyOutput() const;

  /** Return entropy texture value. */
  MeasurementType GetEntropy() const;
  const MeasurementObjectType* GetEntropyOutput() const;

  /** return correlation texture value. */
  MeasurementType GetCorrelation() const;
  const MeasurementObjectType* GetCorrelationOutput() const;

  /** Return inverse difference moment texture value. */
  MeasurementType GetInverseDifferenceMoment() const;
  const MeasurementObjectType* GetInverseDifferenceMomentOutput() const;
  /** Return inertia texture value. */
  MeasurementType GetInertia() const;
  const MeasurementObjectType* GetInertiaOutput() const;

  /** Return cluster shade texture value. */
  MeasurementType GetClusterShade() const;
  const MeasurementObjectType* GetClusterShadeOutput() const;

  /** Return cluster prominence texture value. */
  MeasurementType GetClusterProminence() const;
  const MeasurementObjectType* GetClusterProminenceOutput() const;

  /** Return Haralick correlation texture value. */
  MeasurementType GetHaralickCorrelation() const;
  const MeasurementObjectType* GetHaralickCorrelationOutput() const;
  
  /** Texture feature types */
  typedef enum 
    { 
    Energy,
    Entropy,
    Correlation,
    InverseDifferenceMoment,
    Inertia,
    ClusterShade,
    ClusterProminence,
    HaralickCorrelation,
    InvalidFeatureName
    }  TextureFeatureName;

  /** convenience method to access the texture values */
  MeasurementType GetFeature( TextureFeatureName name );

  
protected:
  HistogramToTextureFeaturesFilter();
  ~HistogramToTextureFeaturesFilter() {};
  void PrintSelf(std::ostream& os, Indent indent) const;

  /** Make a DataObject to be used for output output. */
  virtual DataObjectPointer MakeOutput( unsigned int );


  void GenerateData();

private:
  HistogramToTextureFeaturesFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

  void ComputeMeansAndVariances( double &pixelMean, double &marginalMean, 
    double &marginalDevSquared, double &pixelVariance );

  RelativeFrequencyContainerType             m_RelativeFrequencyContainer;
};
    
    
} // end of namespace Statistics 
} // end of namespace itk 

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkHistogramToTextureFeaturesFilter.txx"
#endif

#endif