Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGIFCooccurenceMatrix.cpp
Go to the documentation of this file.
2 
3 // MITK
4 #include <mitkITKImageImport.h>
5 #include <mitkImageCast.h>
6 #include <mitkImageAccessByItk.h>
7 
8 // ITK
10 #include <itkMinimumMaximumImageCalculator.h>
11 
12 // STL
13 #include <sstream>
14 
15 template<typename TPixel, unsigned int VImageDimension>
16 void
18 {
19  typedef itk::Image<TPixel, VImageDimension> ImageType;
20  typedef itk::Image<TPixel, VImageDimension> MaskType;
22  typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxComputerType;
23  typedef typename FilterType::TextureFeaturesFilterType TextureFilterType;
24 
25  typename MaskType::Pointer maskImage = MaskType::New();
26  mitk::CastToItkImage(mask, maskImage);
27 
28  typename FilterType::Pointer filter = FilterType::New();
29 
31  auto oldOffsets = filter->GetOffsets();
32  auto oldOffsetsIterator = oldOffsets->Begin();
33  while(oldOffsetsIterator != oldOffsets->End())
34  {
35  bool continueOuterLoop = false;
36  typename FilterType::OffsetType offset = oldOffsetsIterator->Value();
37  for (unsigned int i = 0; i < VImageDimension; ++i)
38  {
39  offset[i] *= config.range;
40  if (config.direction == i + 2 && offset[i] != 0)
41  {
42  continueOuterLoop = true;
43  }
44  }
45  if (config.direction == 1)
46  {
47  offset[0] = 0;
48  offset[1] = 0;
49  offset[2] = 1;
50  newOffset->push_back(offset);
51  break;
52  }
53 
54 
55  oldOffsetsIterator++;
56  if (continueOuterLoop)
57  continue;
58  newOffset->push_back(offset);
59 
60  }
61  filter->SetOffsets(newOffset);
62 
63  // All features are required
64  typename FilterType::FeatureNameVectorPointer requestedFeatures = FilterType::FeatureNameVector::New();
65  requestedFeatures->push_back(TextureFilterType::Energy);
66  requestedFeatures->push_back(TextureFilterType::Entropy);
67  requestedFeatures->push_back(TextureFilterType::Correlation);
68  requestedFeatures->push_back(TextureFilterType::InverseDifferenceMoment);
69  requestedFeatures->push_back(TextureFilterType::Inertia);
70  requestedFeatures->push_back(TextureFilterType::ClusterShade);
71  requestedFeatures->push_back(TextureFilterType::ClusterProminence);
72  requestedFeatures->push_back(TextureFilterType::HaralickCorrelation);
73  requestedFeatures->push_back(TextureFilterType::Autocorrelation);
74  requestedFeatures->push_back(TextureFilterType::Contrast);
75  requestedFeatures->push_back(TextureFilterType::Dissimilarity);
76  requestedFeatures->push_back(TextureFilterType::MaximumProbability);
77  requestedFeatures->push_back(TextureFilterType::InverseVariance);
78  requestedFeatures->push_back(TextureFilterType::Homogeneity1);
79  requestedFeatures->push_back(TextureFilterType::ClusterTendency);
80  requestedFeatures->push_back(TextureFilterType::Variance);
81  requestedFeatures->push_back(TextureFilterType::SumAverage);
82  requestedFeatures->push_back(TextureFilterType::SumEntropy);
83  requestedFeatures->push_back(TextureFilterType::SumVariance);
84  requestedFeatures->push_back(TextureFilterType::DifferenceAverage);
85  requestedFeatures->push_back(TextureFilterType::DifferenceEntropy);
86  requestedFeatures->push_back(TextureFilterType::DifferenceVariance);
87  requestedFeatures->push_back(TextureFilterType::InverseDifferenceMomentNormalized);
88  requestedFeatures->push_back(TextureFilterType::InverseDifferenceNormalized);
89  requestedFeatures->push_back(TextureFilterType::InverseDifference);
90 
91  typename MinMaxComputerType::Pointer minMaxComputer = MinMaxComputerType::New();
92  minMaxComputer->SetImage(itkImage);
93  minMaxComputer->Compute();
94 
95  filter->SetInput(itkImage);
96  filter->SetMaskImage(maskImage);
97  filter->SetRequestedFeatures(requestedFeatures);
98  filter->SetPixelValueMinMax(minMaxComputer->GetMinimum()-0.5,minMaxComputer->GetMaximum()+0.5);
99  //filter->SetPixelValueMinMax(-1024,3096);
100  //filter->SetNumberOfBinsPerAxis(5);
101  filter->Update();
102 
103  auto featureMeans = filter->GetFeatureMeans ();
104  auto featureStd = filter->GetFeatureStandardDeviations();
105 
106  std::ostringstream ss;
107  ss << config.range;
108  std::string strRange = ss.str();
109  for (std::size_t i = 0; i < featureMeans->size(); ++i)
110  {
111  switch (i)
112  {
113  case TextureFilterType::Energy :
114  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Energy Means",featureMeans->ElementAt(i)));
115  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Energy Std.",featureStd->ElementAt(i)));
116  break;
117  case TextureFilterType::Entropy :
118  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Entropy Means",featureMeans->ElementAt(i)));
119  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Entropy Std.",featureStd->ElementAt(i)));
120  break;
121  case TextureFilterType::Correlation :
122  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Correlation Means",featureMeans->ElementAt(i)));
123  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Correlation Std.",featureStd->ElementAt(i)));
124  break;
125  case TextureFilterType::InverseDifferenceMoment :
126  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifferenceMoment Means",featureMeans->ElementAt(i)));
127  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifferenceMoment Std.",featureStd->ElementAt(i)));
128  break;
129  case TextureFilterType::Inertia :
130  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Inertia Means",featureMeans->ElementAt(i)));
131  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Inertia Std.",featureStd->ElementAt(i)));
132  break;
133  case TextureFilterType::ClusterShade :
134  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") ClusterShade Means",featureMeans->ElementAt(i)));
135  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") ClusterShade Std.",featureStd->ElementAt(i)));
136  break;
137  case TextureFilterType::ClusterProminence :
138  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") ClusterProminence Means",featureMeans->ElementAt(i)));
139  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") ClusterProminence Std.",featureStd->ElementAt(i)));
140  break;
141  case TextureFilterType::HaralickCorrelation :
142  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") HaralickCorrelation Means",featureMeans->ElementAt(i)));
143  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") HaralickCorrelation Std.",featureStd->ElementAt(i)));
144  break;
145  case TextureFilterType::Autocorrelation :
146  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Autocorrelation Means",featureMeans->ElementAt(i)));
147  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Autocorrelation Std.",featureStd->ElementAt(i)));
148  break;
149  case TextureFilterType::Contrast :
150  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Contrast Means",featureMeans->ElementAt(i)));
151  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Contrast Std.",featureStd->ElementAt(i)));
152  break;
153  case TextureFilterType::Dissimilarity :
154  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Dissimilarity Means",featureMeans->ElementAt(i)));
155  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Dissimilarity Std.",featureStd->ElementAt(i)));
156  break;
157  case TextureFilterType::MaximumProbability :
158  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") MaximumProbability Means",featureMeans->ElementAt(i)));
159  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") MaximumProbability Std.",featureStd->ElementAt(i)));
160  break;
161  case TextureFilterType::InverseVariance :
162  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseVariance Means",featureMeans->ElementAt(i)));
163  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseVariance Std.",featureStd->ElementAt(i)));
164  break;
165  case TextureFilterType::Homogeneity1 :
166  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Homogeneity1 Means",featureMeans->ElementAt(i)));
167  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Homogeneity1 Std.",featureStd->ElementAt(i)));
168  break;
169  case TextureFilterType::ClusterTendency :
170  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") ClusterTendency Means",featureMeans->ElementAt(i)));
171  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") ClusterTendency Std.",featureStd->ElementAt(i)));
172  break;
173  case TextureFilterType::Variance :
174  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Variance Means",featureMeans->ElementAt(i)));
175  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") Variance Std.",featureStd->ElementAt(i)));
176  break;
177  case TextureFilterType::SumAverage :
178  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") SumAverage Means",featureMeans->ElementAt(i)));
179  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") SumAverage Std.",featureStd->ElementAt(i)));
180  break;
181  case TextureFilterType::SumEntropy :
182  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") SumEntropy Means",featureMeans->ElementAt(i)));
183  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") SumEntropy Std.",featureStd->ElementAt(i)));
184  break;
185  case TextureFilterType::SumVariance :
186  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") SumVariance Means",featureMeans->ElementAt(i)));
187  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") SumVariance Std.",featureStd->ElementAt(i)));
188  break;
189  case TextureFilterType::DifferenceAverage :
190  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") DifferenceAverage Means",featureMeans->ElementAt(i)));
191  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") DifferenceAverage Std.",featureStd->ElementAt(i)));
192  break;
193  case TextureFilterType::DifferenceEntropy :
194  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") DifferenceEntropy Means",featureMeans->ElementAt(i)));
195  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") DifferenceEntropy Std.",featureStd->ElementAt(i)));
196  break;
197  case TextureFilterType::DifferenceVariance :
198  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") DifferenceVariance Means",featureMeans->ElementAt(i)));
199  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") DifferenceVariance Std.",featureStd->ElementAt(i)));
200  break;
201  case TextureFilterType::InverseDifferenceMomentNormalized :
202  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifferenceMomentNormalized Means",featureMeans->ElementAt(i)));
203  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifferenceMomentNormalized Std.",featureStd->ElementAt(i)));
204  break;
205  case TextureFilterType::InverseDifferenceNormalized :
206  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifferenceNormalized Means",featureMeans->ElementAt(i)));
207  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifferenceNormalized Std.",featureStd->ElementAt(i)));
208  break;
209  case TextureFilterType::InverseDifference :
210  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifference Means",featureMeans->ElementAt(i)));
211  featureList.push_back(std::make_pair("co-occ. ("+ strRange+") InverseDifference Std.",featureStd->ElementAt(i)));
212  break;
213  default:
214  break;
215  }
216  }
217 }
218 
220 m_Range(1.0), m_Direction(0)
221 {
222 }
223 
225 {
226  FeatureListType featureList;
227 
229  config.direction = m_Direction;
230  config.range = m_Range;
231 
232  AccessByItk_3(image, CalculateCoocurenceFeatures, mask, featureList,config);
233 
234  return featureList;
235 }
236 
238 {
239  FeatureNameListType featureList;
240  featureList.push_back("co-occ. Energy Means");
241  featureList.push_back("co-occ. Energy Std.");
242  featureList.push_back("co-occ. Entropy Means");
243  featureList.push_back("co-occ. Entropy Std.");
244  featureList.push_back("co-occ. Correlation Means");
245  featureList.push_back("co-occ. Correlation Std.");
246  featureList.push_back("co-occ. InverseDifferenceMoment Means");
247  featureList.push_back("co-occ. InverseDifferenceMoment Std.");
248  featureList.push_back("co-occ. Inertia Means");
249  featureList.push_back("co-occ. Inertia Std.");
250  featureList.push_back("co-occ. ClusterShade Means");
251  featureList.push_back("co-occ. ClusterShade Std.");
252  featureList.push_back("co-occ. ClusterProminence Means");
253  featureList.push_back("co-occ. ClusterProminence Std.");
254  featureList.push_back("co-occ. HaralickCorrelation Means");
255  featureList.push_back("co-occ. HaralickCorrelation Std.");
256  featureList.push_back("co-occ. Autocorrelation Means");
257  featureList.push_back("co-occ. Autocorrelation Std.");
258  featureList.push_back("co-occ. Contrast Means");
259  featureList.push_back("co-occ. Contrast Std.");
260  featureList.push_back("co-occ. Dissimilarity Means");
261  featureList.push_back("co-occ. Dissimilarity Std.");
262  featureList.push_back("co-occ. MaximumProbability Means");
263  featureList.push_back("co-occ. MaximumProbability Std.");
264  featureList.push_back("co-occ. InverseVariance Means");
265  featureList.push_back("co-occ. InverseVariance Std.");
266  featureList.push_back("co-occ. Homogeneity1 Means");
267  featureList.push_back("co-occ. Homogeneity1 Std.");
268  featureList.push_back("co-occ. ClusterTendency Means");
269  featureList.push_back("co-occ. ClusterTendency Std.");
270  featureList.push_back("co-occ. Variance Means");
271  featureList.push_back("co-occ. Variance Std.");
272  featureList.push_back("co-occ. SumAverage Means");
273  featureList.push_back("co-occ. SumAverage Std.");
274  featureList.push_back("co-occ. SumEntropy Means");
275  featureList.push_back("co-occ. SumEntropy Std.");
276  featureList.push_back("co-occ. SumVariance Means");
277  featureList.push_back("co-occ. SumVariance Std.");
278  featureList.push_back("co-occ. DifferenceAverage Means");
279  featureList.push_back("co-occ. DifferenceAverage Std.");
280  featureList.push_back("co-occ. DifferenceEntropy Means");
281  featureList.push_back("co-occ. DifferenceEntropy Std.");
282  featureList.push_back("co-occ. DifferenceVariance Means");
283  featureList.push_back("co-occ. DifferenceVariance Std.");
284  featureList.push_back("co-occ. InverseDifferenceMomentNormalized Means");
285  featureList.push_back("co-occ. InverseDifferenceMomentNormalized Std.");
286  featureList.push_back("co-occ. InverseDifferenceNormalized Means");
287  featureList.push_back("co-occ. InverseDifferenceNormalized Std.");
288  featureList.push_back("co-occ. InverseDifference Means");
289  featureList.push_back("co-occ. InverseDifference Std.");
290  return featureList;
291 }
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
itk::SmartPointer< Self > Pointer
void CalculateCoocurenceFeatures(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer mask, mitk::GIFCooccurenceMatrix::FeatureListType &featureList, mitk::GIFCooccurenceMatrix::GIFCooccurenceMatrixConfiguration config)
itk::Image< unsigned char, 3 > ImageType
std::vector< std::pair< std::string, double > > FeatureListType
static Vector3D offset
virtual FeatureListType CalculateFeatures(const Image::Pointer &image, const Image::Pointer &feature) override
Calculates the Cooccurence-Matrix based features for this class.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
virtual FeatureNameListType GetFeatureNames() override
Returns a list of the names of all features that are calculated from this class.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.