iRoCS Toolbox  1.1.0
iRoCSFeatures.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 #ifndef IROCSFEATURES_HH
24 #define IROCSFEATURES_HH
25 
26 #ifdef HAVE_CONFIG_H
27 #include <config.hh>
28 #endif
29 
36 #include <libArrayToolbox/iRoCS.hh>
37 
38 #include <libsvmtl/BasicFV.hh>
39 
40 namespace iRoCS
41 {
42 
43  class Features
44  {
45 
46  public:
47 
49  {
50  None = 0x0000,
52  UnitNorm = 0x0002,
53  Combined = 0x0003,
54  Invalid = 0xffff
55  };
56 
57  static std::string normalizationTypeToString(NormalizationType type);
59  std::string const &normTypeString);
60 
61  static const int PositiveMagnitude;
62  static const int NegativeMagnitude;
63  static const int PositiveRadius;
64  static const int NegativeRadius;
65 
66  Features(
67  blitz::TinyVector<double,3> const &featureElementSizeUm = 1.0,
68  iRoCS::ProgressReporter *progress = NULL);
69  ~Features();
70 
71  blitz::TinyVector<double,3> const &elementSizeUm() const;
72 
73 /*======================================================================*/
85 /*======================================================================*/
86  void addFeatureToGroup(
87  std::string const &groupName, std::string const &featureName);
88 
90  std::string const &groupName, NormalizationType normType);
91 
92  template<typename DataT>
94  atb::Array<DataT,3> const &data, std::string const &cacheFileName);
95 
96  std::string sdFeatureName(atb::SDMagFeatureIndex const &index) const;
97 
98  template<typename DataT>
100  atb::Array<DataT,3> const &data, atb::SDMagFeatureIndex const &index,
101  const int maxBand, std::string const &cacheFileName);
102 
103  std::string houghFeatureName(const int state) const;
104 
105  template<typename DataT>
107  atb::Array<DataT,3> const &data, const int state,
108  std::string const &cacheFileName);
109 
110  template<typename DataT>
112  atb::Array<DataT,3> const &data, atb::IRoCS const &rct,
113  std::string const &cacheFileName);
114 
115  void deleteFeature(atb::SDMagFeatureIndex const &index);
116 
117  void deleteFeature(const int state);
118 
120  std::vector< blitz::TinyVector<double,3> > &markers,
121  blitz::TinyVector<double,3> const &upperBoundUm,
122  int nInRootSamples, int nOutRootSamples);
123 
124  void normalizeFeatures(std::vector<svt::BasicFV> &samples);
125 
126  void saveNormalizationParameters(std::string const &modelFileName);
127 
128  void loadNormalizationParameters(std::string const &modelFileName);
129 
130  void trainTwoClassSVM(
131  std::vector<svt::BasicFV> &trainVectors,
132  std::string const &modelFileName,
133  float cost, float gamma);
134 
135  void classifyTwoClassSVM(
136  std::vector<svt::BasicFV>& testVectors,
137  std::string const &modelFileName);
138 
139  void trainMultiClassSVM(
140  std::vector<svt::BasicFV> &trainVectors,
141  std::string const &modelFileName,
142  float cost, float gamma);
143 
145  std::vector<svt::BasicFV>& testVectors,
146  std::string const &modelFileName);
147 
148  static std::string h5GroupName(const std::string& rawGroup);
149 
150  private:
151 
152  iRoCS::ProgressReporter *p_progress;
153 
154  std::map<int,std::string> _houghDsNames;
155 
156  atb::Array<double,3> _dataScaled;
157  std::map< atb::SDMagFeatureIndex, atb::Array<double,3> > _sdFeatures;
158  std::map< int, atb::Array<double,3> > _houghFeatures;
159  atb::Array<blitz::TinyVector<double,3>,3> _intrinsicCoordinates;
160 
161  std::string _featureBaseGroup;
162  std::vector<std::string> _featureGroups;
163  std::vector<NormalizationType> _normalize;
164  std::vector< std::vector<std::string> > _featureNames;
165  std::vector< std::vector<double> > _means, _stddevs;
166 
167  };
168 
169 }
170 
171 #include "iRoCSFeatures.icc"
172 
173 #endif
atb::Array< blitz::TinyVector< double, 3 >, 3 > & intrinsicCoordinates(atb::Array< DataT, 3 > const &data, atb::IRoCS const &rct, std::string const &cacheFileName)
Features(blitz::TinyVector< double, 3 > const &featureElementSizeUm=1.0, iRoCS::ProgressReporter *progress=NULL)
static std::string normalizationTypeToString(NormalizationType type)
Classes and functions for n-D separable convolution.
atb::Array< double, 3 > & houghFeature(atb::Array< DataT, 3 > const &data, const int state, std::string const &cacheFileName)
static NormalizationType stringToNormalizationType(std::string const &normTypeString)
The IRoCS class provides means to attach iRoCS to different kinds of processed root images...
Definition: iRoCS.hh:69
void generateRandomSamples(std::vector< blitz::TinyVector< double, 3 > > &markers, blitz::TinyVector< double, 3 > const &upperBoundUm, int nInRootSamples, int nOutRootSamples)
void trainMultiClassSVM(std::vector< svt::BasicFV > &trainVectors, std::string const &modelFileName, float cost, float gamma)
void classifyMultiClassSVM(std::vector< svt::BasicFV > &testVectors, std::string const &modelFileName)
static const int NegativeRadius
void normalizeFeatures(std::vector< svt::BasicFV > &samples)
void classifyTwoClassSVM(std::vector< svt::BasicFV > &testVectors, std::string const &modelFileName)
blitz::TinyVector< double, 3 > const & elementSizeUm() const
The Implementation of the filter computing the Laplacian of the input data using Forward-backward-dif...
std::string houghFeatureName(const int state) const
Structures and functions for spherical tensor extraction and arithmetics.
atb::Array< double, 3 > & sdFeature(atb::Array< DataT, 3 > const &data, atb::SDMagFeatureIndex const &index, const int maxBand, std::string const &cacheFileName)
static const int PositiveMagnitude
atb::Array< double, 3 > & dataScaled(atb::Array< DataT, 3 > const &data, std::string const &cacheFileName)
static std::string h5GroupName(const std::string &rawGroup)
void saveNormalizationParameters(std::string const &modelFileName)
Data structure to index a feature structure consisting of multi-scale spherical derivative features...
The intrinsic root coordinate system.
void addFeatureToGroup(std::string const &groupName, std::string const &featureName)
Adds a new feature name to the specified group.
void loadNormalizationParameters(std::string const &modelFileName)
std::string sdFeatureName(atb::SDMagFeatureIndex const &index) const
static const int PositiveRadius
void setGroupNormalization(std::string const &groupName, NormalizationType normType)
void trainTwoClassSVM(std::vector< svt::BasicFV > &trainVectors, std::string const &modelFileName, float cost, float gamma)
void deleteFeature(atb::SDMagFeatureIndex const &index)
static const int NegativeMagnitude