Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGIFGrayLevelRunLength.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 // MITK
20 #include <mitkITKImageImport.h>
21 #include <mitkImageCast.h>
22 #include <mitkImageAccessByItk.h>
23 
24 // ITK
26 #include <itkMinimumMaximumImageCalculator.h>
27 
28 // STL
29 #include <sstream>
30 
31 template<typename TPixel, unsigned int VImageDimension>
32 void
34 {
35  typedef itk::Image<TPixel, VImageDimension> ImageType;
36  typedef itk::Image<TPixel, VImageDimension> MaskType;
38  typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxComputerType;
39  typedef typename FilterType::RunLengthFeaturesFilterType TextureFilterType;
40 
41  typename MaskType::Pointer maskImage = MaskType::New();
42  mitk::CastToItkImage(mask, maskImage);
43 
44  typename FilterType::Pointer filter = FilterType::New();
45 
47  auto oldOffsets = filter->GetOffsets();
48  auto oldOffsetsIterator = oldOffsets->Begin();
49  while (oldOffsetsIterator != oldOffsets->End())
50  {
51  bool continueOuterLoop = false;
52  typename FilterType::OffsetType offset = oldOffsetsIterator->Value();
53  for (unsigned int i = 0; i < VImageDimension; ++i)
54  {
55  if (params.m_Direction == i + 2 && offset[i] != 0)
56  {
57  continueOuterLoop = true;
58  }
59  }
60  if (params.m_Direction == 1)
61  {
62  offset[0] = 0;
63  offset[1] = 0;
64  offset[2] = 1;
65  newOffset->push_back(offset);
66  break;
67  }
68 
69  oldOffsetsIterator++;
70  if (continueOuterLoop)
71  continue;
72  newOffset->push_back(offset);
73  }
74  filter->SetOffsets(newOffset);
75 
76 
77  // All features are required
78  typename FilterType::FeatureNameVectorPointer requestedFeatures = FilterType::FeatureNameVector::New();
79  requestedFeatures->push_back(TextureFilterType::ShortRunEmphasis);
80  requestedFeatures->push_back(TextureFilterType::LongRunEmphasis);
81  requestedFeatures->push_back(TextureFilterType::GreyLevelNonuniformity);
82  requestedFeatures->push_back(TextureFilterType::RunLengthNonuniformity);
83  requestedFeatures->push_back(TextureFilterType::LowGreyLevelRunEmphasis);
84  requestedFeatures->push_back(TextureFilterType::HighGreyLevelRunEmphasis);
85  requestedFeatures->push_back(TextureFilterType::ShortRunLowGreyLevelEmphasis);
86  requestedFeatures->push_back(TextureFilterType::ShortRunHighGreyLevelEmphasis);
87  requestedFeatures->push_back(TextureFilterType::LongRunLowGreyLevelEmphasis);
88  requestedFeatures->push_back(TextureFilterType::LongRunHighGreyLevelEmphasis);
89  requestedFeatures->push_back(TextureFilterType::RunPercentage);
90  requestedFeatures->push_back(TextureFilterType::NumberOfRuns);
91 
92  typename MinMaxComputerType::Pointer minMaxComputer = MinMaxComputerType::New();
93  minMaxComputer->SetImage(itkImage);
94  minMaxComputer->Compute();
95 
96  filter->SetInput(itkImage);
97  filter->SetMaskImage(maskImage);
98  filter->SetRequestedFeatures(requestedFeatures);
99  int rangeOfPixels = params.m_Range;
100  if (rangeOfPixels < 2)
101  rangeOfPixels = 256;
102 
103  if (params.m_UseCtRange)
104  {
105  filter->SetPixelValueMinMax((TPixel)(-1024.5),(TPixel)(3096.5));
106  filter->SetNumberOfBinsPerAxis(3096.5+1024.5);
107  } else
108  {
109  filter->SetPixelValueMinMax(minMaxComputer->GetMinimum(),minMaxComputer->GetMaximum());
110  filter->SetNumberOfBinsPerAxis(rangeOfPixels);
111  }
112 
113  filter->SetDistanceValueMinMax(0,rangeOfPixels);
114 
115  filter->Update();
116 
117  auto featureMeans = filter->GetFeatureMeans ();
118  auto featureStd = filter->GetFeatureStandardDeviations();
119 
120  std::ostringstream ss;
121  ss << rangeOfPixels;
122  std::string strRange = ss.str();
123  for (std::size_t i = 0; i < featureMeans->size(); ++i)
124  {
125  switch (i)
126  {
127  case TextureFilterType::ShortRunEmphasis :
128  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") ShortRunEmphasis Means",featureMeans->ElementAt(i)));
129  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") ShortRunEmphasis Std.",featureStd->ElementAt(i)));
130  break;
131  case TextureFilterType::LongRunEmphasis :
132  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LongRunEmphasis Means",featureMeans->ElementAt(i)));
133  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LongRunEmphasis Std.",featureStd->ElementAt(i)));
134  break;
135  case TextureFilterType::GreyLevelNonuniformity :
136  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") GreyLevelNonuniformity Means",featureMeans->ElementAt(i)));
137  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") GreyLevelNonuniformity Std.",featureStd->ElementAt(i)));
138  break;
139  case TextureFilterType::RunLengthNonuniformity :
140  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") RunLengthNonuniformity Means",featureMeans->ElementAt(i)));
141  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") RunLengthNonuniformity Std.",featureStd->ElementAt(i)));
142  break;
143  case TextureFilterType::LowGreyLevelRunEmphasis :
144  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LowGreyLevelRunEmphasis Means",featureMeans->ElementAt(i)));
145  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LowGreyLevelRunEmphasis Std.",featureStd->ElementAt(i)));
146  break;
147  case TextureFilterType::HighGreyLevelRunEmphasis :
148  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") HighGreyLevelRunEmphasis Means",featureMeans->ElementAt(i)));
149  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") HighGreyLevelRunEmphasis Std.",featureStd->ElementAt(i)));
150  break;
151  case TextureFilterType::ShortRunLowGreyLevelEmphasis :
152  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") ShortRunLowGreyLevelEmphasis Means",featureMeans->ElementAt(i)));
153  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") ShortRunLowGreyLevelEmphasis Std.",featureStd->ElementAt(i)));
154  break;
155  case TextureFilterType::ShortRunHighGreyLevelEmphasis :
156  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") ShortRunHighGreyLevelEmphasis Means",featureMeans->ElementAt(i)));
157  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") ShortRunHighGreyLevelEmphasis Std.",featureStd->ElementAt(i)));
158  break;
159  case TextureFilterType::LongRunLowGreyLevelEmphasis :
160  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LongRunLowGreyLevelEmphasis Means",featureMeans->ElementAt(i)));
161  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LongRunLowGreyLevelEmphasis Std.",featureStd->ElementAt(i)));
162  break;
163  case TextureFilterType::LongRunHighGreyLevelEmphasis :
164  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LongRunHighGreyLevelEmphasis Means",featureMeans->ElementAt(i)));
165  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") LongRunHighGreyLevelEmphasis Std.",featureStd->ElementAt(i)));
166  break;
167  case TextureFilterType::RunPercentage :
168  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") RunPercentage Means",featureMeans->ElementAt(i)));
169  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") RunPercentage Std.",featureStd->ElementAt(i)));
170  break;
171  case TextureFilterType::NumberOfRuns :
172  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") NumberOfRuns Means",featureMeans->ElementAt(i)));
173  featureList.push_back(std::make_pair("RunLength. ("+ strRange+") NumberOfRuns Std.",featureStd->ElementAt(i)));
174  break;
175  default:
176  break;
177  }
178  }
179 }
180 
182 m_Range(1.0), m_UseCtRange(false), m_Direction(0)
183 {
184 }
185 
187 {
188  FeatureListType featureList;
189 
190  ParameterStruct params;
191  params.m_UseCtRange=m_UseCtRange;
192  params.m_Range = m_Range;
193  params.m_Direction = m_Direction;
194 
195  AccessByItk_3(image, CalculateGrayLevelRunLengthFeatures, mask, featureList,params);
196 
197  return featureList;
198 }
199 
201 {
202  FeatureNameListType featureList;
203  featureList.push_back("RunLength. ShortRunEmphasis Means");
204  featureList.push_back("RunLength. ShortRunEmphasis Std.");
205  featureList.push_back("RunLength. LongRunEmphasis Means");
206  featureList.push_back("RunLength. LongRunEmphasis Std.");
207  featureList.push_back("RunLength. GreyLevelNonuniformity Means");
208  featureList.push_back("RunLength. GreyLevelNonuniformity Std.");
209  featureList.push_back("RunLength. RunLengthNonuniformity Means");
210  featureList.push_back("RunLength. RunLengthNonuniformity Std.");
211  featureList.push_back("RunLength. LowGreyLevelRunEmphasis Means");
212  featureList.push_back("RunLength. LowGreyLevelRunEmphasis Std.");
213  featureList.push_back("RunLength. HighGreyLevelRunEmphasis Means");
214  featureList.push_back("RunLength. HighGreyLevelRunEmphasis Std.");
215  featureList.push_back("RunLength. ShortRunLowGreyLevelEmphasis Means");
216  featureList.push_back("RunLength. ShortRunLowGreyLevelEmphasis Std.");
217  featureList.push_back("RunLength. ShortRunHighGreyLevelEmphasis Means");
218  featureList.push_back("RunLength. ShortRunHighGreyLevelEmphasis Std.");
219  featureList.push_back("RunLength. LongRunHighGreyLevelEmphasis Means");
220  featureList.push_back("RunLength. LongRunHighGreyLevelEmphasis Std.");
221  return featureList;
222 }
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
itk::SmartPointer< Self > Pointer
itk::Image< unsigned char, 3 > ImageType
void CalculateGrayLevelRunLengthFeatures(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer mask, mitk::GIFGrayLevelRunLength::FeatureListType &featureList, mitk::GIFGrayLevelRunLength::ParameterStruct params)
std::vector< std::pair< std::string, double > > FeatureListType
static Vector3D offset
virtual FeatureNameListType GetFeatureNames() override
Returns a list of the names of all features that are calculated from 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 FeatureListType CalculateFeatures(const Image::Pointer &image, const Image::Pointer &feature) override
Calculates the Cooccurence-Matrix based features for this class.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.