OTB  9.0.0
Orfeo Toolbox
otbGreyLevelCooccurrenceIndexedList.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef otbGreyLevelCooccurrenceIndexedList_h
23 #define otbGreyLevelCooccurrenceIndexedList_h
24 
25 #include "itkNumericTraits.h"
26 #include "itkObjectFactory.h"
27 #include "itkLightObject.h"
28 #include "itkArray.h"
29 #include "itkIndex.h"
30 #include "itkSize.h"
31 #include <utility>
32 #include <vector>
33 
34 namespace otb
35 {
65 template <class TPixel>
66 class ITK_EXPORT GreyLevelCooccurrenceIndexedList : public itk::LightObject
67 {
68 public:
71  typedef itk::LightObject Superclass;
72  typedef itk::SmartPointer<Self> Pointer;
73  typedef itk::SmartPointer<const Self> ConstPointer;
74 
76  itkNewMacro(Self);
77 
79  itkTypeMacro(GreyLevelCooccurrenceIndexedList, itk::LightObject);
80 
81  typedef TPixel PixelType;
82 
83  itkStaticConstMacro(PixelPairSize, unsigned int, 2);
84 
85  typedef itk::Index<PixelPairSize> IndexType;
86  typedef itk::Size<PixelPairSize> SizeType;
87  typedef typename itk::IndexValueType IndexValueType;
88 
89  typedef typename itk::IdentifierType InstanceIdentifier;
91  typedef typename itk::NumericTraits<FrequencyType>::RealType RelativeFrequencyType;
92  typedef typename itk::NumericTraits<FrequencyType>::AccumulateType TotalFrequencyType;
93 
94  typedef typename itk::NumericTraits<PixelType>::RealType PixelValueType;
95  typedef itk::FixedArray<PixelValueType, PixelPairSize> PixelPairType;
96  // lower bound of each bin
97  std::vector<std::vector<PixelValueType>> m_Min;
98  // upper bound of each bin
99  std::vector<std::vector<PixelValueType>> m_Max;
100 
101  /* std::pair to hold pixel pair and its frequency count */
102  typedef std::pair<IndexType, FrequencyType> CooccurrencePairType;
103 
107  typedef itk::Array<int> LookupArrayType;
108 
111  typedef std::vector<CooccurrencePairType> VectorType;
112 
114  itkGetMacro(TotalFrequency, TotalFrequencyType);
115 
117  itkGetMacro(Symmetry, bool);
118 
121 
124  void Initialize(const unsigned int nbins, const PixelValueType min, const PixelValueType max, const bool symmetry = true);
125 
126  // check if both pixel values fall between m_InputImageMinimum and
127  // m_InputImageMaximum. If so add to m_Vector via AddPairToVector method */
128  void AddPixelPair(const PixelValueType& pixelvalue1, const PixelValueType& pixelvalue2);
129 
130  /* Get the frequency value from Vector with index =[j,i] */
132 
133  /* Get the frequency value from Vector with index =[j,i] from given
134  * vector. This is used if we have a copy of m_Vector normalized. */
135  RelativeFrequencyType GetFrequency(IndexValueType i, IndexValueType j, const VectorType& vect) const;
136 
137 protected:
139  ~GreyLevelCooccurrenceIndexedList() override = default;
140 
145  void AddPairToVector(IndexType index);
146 
147  void SetBinMin(const unsigned int dimension, const InstanceIdentifier nbin, PixelValueType min);
148 
149  void SetBinMax(const unsigned int dimension, const InstanceIdentifier nbin, PixelValueType max);
150 
152  bool GetIndex(const PixelPairType& pixelPair, IndexType& index) const;
153 
154  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
155 
156 private:
157  GreyLevelCooccurrenceIndexedList(const Self&) = delete;
158  void operator=(const Self&) = delete;
159 
162 
163  /* std::vector holding actual co-occurrence pairs */
165 
166  /* Size instance */
168 
171 
172  /* Store the total frequency of co-occurrence pairs in GreyLevelCooccureneIndexedList class */
174 
178 
181 
184 };
185 
186 } // End namespace otb
187 
188 #ifndef OTB_MANUAL_INSTANTIATION
190 #endif
191 
192 #endif
otb::GreyLevelCooccurrenceIndexedList::LookupArrayType
itk::Array< int > LookupArrayType
Definition: otbGreyLevelCooccurrenceIndexedList.h:107
otb::GreyLevelCooccurrenceIndexedList::m_LookupArray
LookupArrayType m_LookupArray
Definition: otbGreyLevelCooccurrenceIndexedList.h:161
otb::GreyLevelCooccurrenceIndexedList::m_TotalFrequency
TotalFrequencyType m_TotalFrequency
Definition: otbGreyLevelCooccurrenceIndexedList.h:173
otb::GreyLevelCooccurrenceIndexedList::Self
GreyLevelCooccurrenceIndexedList Self
Definition: otbGreyLevelCooccurrenceIndexedList.h:70
otb::GreyLevelCooccurrenceIndexedList::RelativeFrequencyType
itk::NumericTraits< FrequencyType >::RealType RelativeFrequencyType
Definition: otbGreyLevelCooccurrenceIndexedList.h:91
otb::GreyLevelCooccurrenceIndexedList::m_Symmetry
bool m_Symmetry
Definition: otbGreyLevelCooccurrenceIndexedList.h:170
otb::GreyLevelCooccurrenceIndexedList::PixelValueType
itk::NumericTraits< PixelType >::RealType PixelValueType
Definition: otbGreyLevelCooccurrenceIndexedList.h:94
otb::GreyLevelCooccurrenceIndexedList::m_Vector
VectorType m_Vector
Definition: otbGreyLevelCooccurrenceIndexedList.h:164
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::GreyLevelCooccurrenceIndexedList::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbGreyLevelCooccurrenceIndexedList.h:72
otb::GreyLevelCooccurrenceIndexedList::m_ClipBinsAtEnds
bool m_ClipBinsAtEnds
Definition: otbGreyLevelCooccurrenceIndexedList.h:177
otb::GreyLevelCooccurrenceIndexedList::VectorType
std::vector< CooccurrencePairType > VectorType
Definition: otbGreyLevelCooccurrenceIndexedList.h:111
otb::GreyLevelCooccurrenceIndexedList::InstanceIdentifier
itk::IdentifierType InstanceIdentifier
Definition: otbGreyLevelCooccurrenceIndexedList.h:89
otb::GreyLevelCooccurrenceIndexedList::m_InputImageMaximum
PixelValueType m_InputImageMaximum
Definition: otbGreyLevelCooccurrenceIndexedList.h:183
otb::GreyLevelCooccurrenceIndexedList::Superclass
itk::LightObject Superclass
Definition: otbGreyLevelCooccurrenceIndexedList.h:71
otbGreyLevelCooccurrenceIndexedList.hxx
otb::GreyLevelCooccurrenceIndexedList::m_InputImageMinimum
PixelValueType m_InputImageMinimum
Definition: otbGreyLevelCooccurrenceIndexedList.h:180
otb::GreyLevelCooccurrenceIndexedList::PixelType
TPixel PixelType
Definition: otbGreyLevelCooccurrenceIndexedList.h:79
otb::GreyLevelCooccurrenceIndexedList::FrequencyType
InstanceIdentifier FrequencyType
Definition: otbGreyLevelCooccurrenceIndexedList.h:90
otb::GreyLevelCooccurrenceIndexedList::IndexValueType
itk::IndexValueType IndexValueType
Definition: otbGreyLevelCooccurrenceIndexedList.h:87
otb::GreyLevelCooccurrenceIndexedList::CooccurrencePairType
std::pair< IndexType, FrequencyType > CooccurrencePairType
Definition: otbGreyLevelCooccurrenceIndexedList.h:102
otb::GreyLevelCooccurrenceIndexedList::m_Size
SizeType m_Size
Definition: otbGreyLevelCooccurrenceIndexedList.h:167
otb::GreyLevelCooccurrenceIndexedList::m_Min
std::vector< std::vector< PixelValueType > > m_Min
Definition: otbGreyLevelCooccurrenceIndexedList.h:97
otb::GreyLevelCooccurrenceIndexedList::IndexType
itk::Index< PixelPairSize > IndexType
Definition: otbGreyLevelCooccurrenceIndexedList.h:85
otb::GreyLevelCooccurrenceIndexedList::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbGreyLevelCooccurrenceIndexedList.h:73
otb::Wrapper::MetaDataHelper::GetVector
OTBApplicationEngine_EXPORT otb::MetaDataKey::VectorType GetVector(const itk::MetaDataDictionary &dict, const std::string &key)
otb::GreyLevelCooccurrenceIndexedList::m_Max
std::vector< std::vector< PixelValueType > > m_Max
Definition: otbGreyLevelCooccurrenceIndexedList.h:99
otb::GreyLevelCooccurrenceIndexedList
This class holds a VectorType of CooccurrencePairType with each pair is a combination of pixel index ...
Definition: otbGreyLevelCooccurrenceIndexedList.h:66
otb::GreyLevelCooccurrenceIndexedList::PixelPairType
itk::FixedArray< PixelValueType, PixelPairSize > PixelPairType
Definition: otbGreyLevelCooccurrenceIndexedList.h:95
otb::GreyLevelCooccurrenceIndexedList::SizeType
itk::Size< PixelPairSize > SizeType
Definition: otbGreyLevelCooccurrenceIndexedList.h:86
otb::GreyLevelCooccurrenceIndexedList::TotalFrequencyType
itk::NumericTraits< FrequencyType >::AccumulateType TotalFrequencyType
Definition: otbGreyLevelCooccurrenceIndexedList.h:92