Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkGIFLocalIntensity.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include <mitkGIFLocalIntensity.h>
14 
15 // MITK
16 #include <mitkITKImageImport.h>
17 #include <mitkImageCast.h>
18 #include <mitkImageAccessByItk.h>
19 #include <mitkPixelTypeMultiplex.h>
21 
22 // ITK
23 #include <itkImageRegionIteratorWithIndex.h>
24 #include <itkNeighborhoodIterator.h>
26 
27 // STL
28 #include <limits>
29 
30 struct GIFLocalIntensityParameter
31 {
32  double range;
33  std::string prefix;
34 };
35 
36 
37 template<typename TPixel, unsigned int VImageDimension>
38 static void
39 CalculateIntensityPeak(itk::Image<TPixel, VImageDimension>* itkImage, mitk::Image::Pointer mask, mitk::GIFLocalIntensity::FeatureListType & featureList, GIFLocalIntensityParameter params)
40 {
41  typedef itk::Image<TPixel, VImageDimension> ImageType;
42  typedef itk::Image<unsigned short, VImageDimension> MaskType;
43 
44  typename MaskType::Pointer itkMask = MaskType::New();
45  mitk::CastToItkImage(mask, itkMask);
46 
47  double range = params.range;
48 
50  filter->SetInput(itkImage);
51  filter->SetMask(itkMask);
52  filter->SetRange(range);
53  filter->Update();
54 
55  featureList.push_back(std::make_pair(params.prefix + "2. Local Intensity Peak", filter->GetLocalPeak()));
56  featureList.push_back(std::make_pair(params.prefix + "2. Global Intensity Peak", filter->GetGlobalPeak()));
57 }
58 
59 
61 m_Range(6.2)
62 {
63  SetLongName("local-intensity");
64  SetShortName("loci");
65  SetFeatureClassName("Local Intensity");
66 }
67 
69 {
70  FeatureListType featureList;
71  if (image->GetDimension() < 3)
72  {
73  return featureList;
74  }
75  GIFLocalIntensityParameter params;
76  params.range = GetRange();
77  params.prefix = FeatureDescriptionPrefix();
78  AccessByItk_3(image, CalculateIntensityPeak, mask, featureList, params);
79  return featureList;
80 }
81 
83 {
84  FeatureNameListType featureList;
85  return featureList;
86 }
87 
88 
90 {
91  std::string name = GetOptionPrefix();
92 
93  parser.addArgument(GetLongName(), name, mitkCommandLineParser::Bool, "Use Local Intensity", "calculates local intensity based features", us::Any());
94  parser.addArgument(name + "::range", name+"::range", mitkCommandLineParser::Float, "Range for the local intensity", "Give the range that should be used for the local intensity in mm", us::Any());
95 }
96 
97 void
99 {
100  std::string name = GetOptionPrefix();
101  auto parsedArgs = GetParameter();
102  if (parsedArgs.count(GetLongName()))
103  {
104  if (parsedArgs.count(name + "::range"))
105  {
106  double range = us::any_cast<float>(parsedArgs[name + "::range"]);
107  this->SetRange(range);
108  }
109  MITK_INFO << "Start calculating local intensity features ....";
110  auto localResults = this->CalculateFeatures(feature, mask);
111  featureList.insert(featureList.end(), localResults.begin(), localResults.end());
112  MITK_INFO << "Finished calculating local intensity features....";
113  }
114 }
115 
117 {
118  std::ostringstream ss;
119  ss << m_Range;
120  std::string strRange = ss.str();
121  return "Range-" + ss.str();
122 }
123 
124 
125 
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
void AddArguments(mitkCommandLineParser &parser) override
#define MITK_INFO
Definition: mitkLogMacros.h:18
itk::Image< unsigned char, 3 > ImageType
virtual void SetLongName(std::string _arg)
static void CalculateIntensityPeak(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer mask, mitk::GIFLocalIntensity::FeatureListType &featureList, GIFLocalIntensityParameter params)
static Pointer New()
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
virtual void SetShortName(std::string _arg)
std::vector< std::pair< std::string, double > > FeatureListType
std::string FeatureDescriptionPrefix()
Returns a string that encodes the feature class name.
virtual std::string GetLongName() const
Definition: usAny.h:163
void CalculateFeaturesUsingParameters(const Image::Pointer &feature, const Image::Pointer &mask, const Image::Pointer &maskNoNAN, FeatureListType &featureList) override
Calculates the feature of this abstact interface. Does not necessarily considers the parameter settin...
mitk::Image::Pointer image
virtual double GetRange() const
virtual void SetRange(double _arg)
virtual void SetFeatureClassName(std::string _arg)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
std::string GetCurrentFeatureEncoding() override
Adds an additional Separator to the name of the feature, which encodes the used parameters.
mitk::Image::Pointer mask
FeatureNameListType GetFeatureNames() override
Returns a list of the names of all features that are calculated from this class.
FeatureListType CalculateFeatures(const Image::Pointer &image, const Image::Pointer &feature) override
Calculates the Cooccurence-Matrix based features for this class.
virtual ParameterTypes GetParameter() const