diff --git a/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.h b/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.h index b50d547e5a7eedc6915e7db834bed8c6e3439d95..5b313456a2a09b84e109e133efed32d6b140fdfe 100644 --- a/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.h +++ b/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.h @@ -26,6 +26,66 @@ namespace otb { /** \class GreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator * \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): + * + * "Sum of squares: Variance" \f$ = f_4 = \sum_{i,j}(i -mu)^2 g(i,j) \f$ + * + * "Sum average" \f$ = f_6 = -\sum_{i}i g_{x+y}(i) + * + * "Sum Variance" \f$ = f_7 = \sum_{i}(i - f_8)^2 g_{x+y}(i) \f$ + * + * "Sum Entropy" \f$= f_8 = -\sum_{i}g_{x+y}(i) log (g_{x+y}(i)) \f$ + * + * "Difference variance" \f$ = f_10 = variance of g_{x-y}(i) + * + * "Difference entropy" \f$ = f_11 = -\sum_{i}g_{x-y}(i) log (g_{x-y}(i)) \f$ + * + * "Information Measures of Correlation IC1" \f$ = f_12 = \frac{f_9 - HXY1}{H} \f$ + * + * "Information Measures of Correlation IC2" \f$ = f_13 = \sqrt{1 - \exp{-2}|HXY2 - f_9|} \f$ + * + * 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$ \g_{x+y}(k) = \sum_{i}\sum_{j}g(i)\f$ where \f$ i+j=k \f$ and \f$ k = 2,3,..,2N_[g} \f$ and + * + * \f$ \g_{x-y}(k) = \sum_{i}\sum_{j}g(i)\f$ where \f$ i-j=k \f$ and \f$ k = 0,1,..,N_[g}-1 \f$ + * + * 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 GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator + * \sa ScalarImageTextureCalculator + * */ template < typename THistogram > diff --git a/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.txx b/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.txx index abb226fb155cd0b3d1089d6dea707d8e8ca93acd..22bf0c22c4031ecb2cd86a8f861c789a3c742474 100644 --- a/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.txx +++ b/Code/FeatureExtraction/otbGreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator.txx @@ -23,8 +23,6 @@ namespace otb { - - template< class THistogram > void GreyLevelCooccurrenceMatrixAdvancedTextureCoefficientsCalculator< THistogram >:: @@ -81,8 +79,7 @@ Compute () this->NormalizeHistogram(); } - // Now get the various means and variances. This is takes two passes - // through the histogram. + // Now get the pixel mean. double pixelMean; this->ComputeMean( pixelMean ); @@ -92,6 +89,7 @@ Compute () double PSSquareCumul = 0; double log2 = vcl_log(2.); + // First pass to compute SumAverage, SumVariance for (long unsigned int i = 0 ; i < m_Histogram->GetSize()[0] + m_Histogram->GetSize()[1]; ++i) { double psTmp = ComputePS (i); @@ -110,6 +108,7 @@ Compute () double PDSquareCumul = 0; double PDCumul = 0; + // Second pass to compute DifferenceVariance and DifferenceEntropy for (long unsigned int i = 0 ; i < minSizeHist ; ++i) { double pdTmp = ComputePD (i); @@ -125,6 +124,7 @@ Compute () double hx = 0; double hy = 0; + // Compute hx and hy need to compute f12 and f13 texture coefficients for (long unsigned int i = 0 ; i < m_Histogram->GetSize()[0] ; ++i) { double marginalfreq = m_Histogram->GetFrequency ( i , 0 ); @@ -143,6 +143,7 @@ Compute () m_Variance = 0; double Entropy = 0; + // Third pass over the histogram to compute Sum of squares (variance), entropy (needed for f12) for (HistogramIterator hit = m_Histogram->Begin(); hit != m_Histogram->End(); ++hit) { @@ -159,6 +160,7 @@ Compute () hxy2 -= (pipj > 0.0001) ? pipj * vcl_log ( pipj ) : 0; } + //Finally get f12 and f13 m_IC1 = (vcl_abs( std::max ( hx, hy ) ) > 0.0001) ? ( Entropy - hxy1 ) / (std::max ( hx, hy ) ) : 0; m_IC2 = 1 - vcl_exp ( -2. * vcl_abs ( hxy2 - Entropy ) );