Darwin  1.10(beta)
drwnSegImagePixelFeatures.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2017, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnSegImagePixelFeatures.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <cstdlib>
16 #include <cassert>
17 #include <vector>
18 #include <list>
19 
20 #include "Eigen/Core"
21 
22 #include "drwnBase.h"
23 #include "drwnIO.h"
24 #include "drwnML.h"
25 
26 #include "drwnFilterBankResponse.h"
27 
28 using namespace std;
29 using namespace Eigen;
30 
31 // forward declarations ----------------------------------------------------
32 
34 
35 // drwnSegImagePixelFeatures class -----------------------------------------
48 
50  protected:
51  string _instanceName;
54 
55  public:
56  drwnSegImagePixelFeatures() : _instanceWidth(0), _instanceHeight(0)
57  { /* do nothing */ }
59  _instanceName(pf._instanceName), _instanceWidth(pf._instanceWidth),
60  _instanceHeight(pf._instanceHeight) { /* do nothing */ }
61  virtual ~drwnSegImagePixelFeatures() { /* do nothing */ }
62 
63  drwnSegImagePixelFeatures *clone() const = 0;
64 
66  virtual int numFeatures() const = 0;
67 
69  virtual void cacheInstanceData(const drwnSegImageInstance& instance);
71  virtual void clearInstanceData();
72 
74  virtual void appendPixelFeatures(int x, int y, vector<double>& phi) const = 0;
76  virtual void appendAllPixelFeatures(vector<vector<double> >& phi) const;
77 };
78 
79 // drwnSegImageStdPixelFeatures class --------------------------------------
82 
84  public:
85  // configurable feature options
86  static double FILTER_BANDWIDTH;
87  static int FEATURE_GRID_SPACING;
88  static bool INCLUDE_RGB;
89  static bool INCLUDE_HOG;
90  static bool INCLUDE_LBP;
91  static bool INCLUDE_ROWCOLAGG;
92  static bool INCLUDE_LOCATION;
93  static string AUX_FEATURE_DIR;
94  static vector<string> AUX_FEATURE_EXT;
95 
96  protected:
98  vector<vector<double> > _auxFeatures;
99 
100  public:
101  drwnSegImageStdPixelFeatures() { /* do nothing */ }
103  virtual ~drwnSegImageStdPixelFeatures() { /* do nothing */ }
104 
106  return new drwnSegImageStdPixelFeatures(*this);
107  }
108 
109  // data caching
110  void cacheInstanceData(const drwnSegImageInstance& instance);
111  void clearInstanceData();
112 
113  // feature computation
114  int numFeatures() const;
115  void appendPixelFeatures(int x, int y, vector<double>& phi) const;
116 };
117 
118 // drwnSegImageFilePixelFeatures class -------------------------------------
120 
122  public:
123  string featuresDir;
124  list<string> featuresExt;
125 
126  protected:
127  vector<vector<double> > _features;
128 
129  public:
130  drwnSegImageFilePixelFeatures() { /* do nothing */ }
132  virtual ~drwnSegImageFilePixelFeatures() { /* do nothing */ }
133 
135  return new drwnSegImageFilePixelFeatures(*this);
136  }
137 
138  // data caching
139  void cacheInstanceData(const drwnSegImageInstance& instance);
140  void clearInstanceData();
141 
142  // feature computation
143  int numFeatures() const;
144  void appendPixelFeatures(int x, int y, vector<double>& phi) const;
145 };
146 
147 // drwnSegImageCompositePixelFeatures class --------------------------------
149 
151  protected:
152  int _numFeatures;
153  std::list<drwnSegImagePixelFeatures *> _featureGenerators;
154 
155  public:
156  drwnSegImageCompositePixelFeatures() : _numFeatures(0) { /* do nothing */ }
159 
161  return new drwnSegImageCompositePixelFeatures(*this);
162  }
163 
164  // data caching
165  void cacheInstanceData(const drwnSegImageInstance& instance);
166  void clearInstanceData();
167 
168  // feature computation
169  int numFeatures() const { return _numFeatures; }
170  void appendPixelFeatures(int x, int y, vector<double>& phi) const;
171  void appendAllPixelFeatures(vector<vector<double> >& phi) const;
172 
174  void clearFeatureGenerators();
176  void addFeatureGenerator(drwnSegImagePixelFeatures *generator);
179  DRWN_ASSERT(generator != NULL);
180  addFeatureGenerator(generator->clone());
181  }
182 };
static bool INCLUDE_LOCATION
flag to include location features
Definition: drwnSegImagePixelFeatures.h:92
Class for generating composite per-pixel feature vectors.
Definition: drwnSegImagePixelFeatures.h:150
Encapsulates a single instance of an image for multi-class pixel labeling problems (i...
Definition: drwnSegImageInstance.h:47
static string AUX_FEATURE_DIR
directory for auxiliary features
Definition: drwnSegImagePixelFeatures.h:93
string _instanceName
name of the chached instance (for error reporting)
Definition: drwnSegImagePixelFeatures.h:51
int _instanceWidth
height of the cached instance
Definition: drwnSegImagePixelFeatures.h:52
drwnSegImageFilePixelFeatures * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnSegImagePixelFeatures.h:134
void copyFeatureGenerator(const drwnSegImagePixelFeatures *generator)
copy feature generator (caller must free)
Definition: drwnSegImagePixelFeatures.h:178
list< string > featuresExt
feature file extensions
Definition: drwnSegImagePixelFeatures.h:124
Holds the results of running an image through a bank of filters and allows for computation of feature...
Definition: drwnFilterBankResponse.h:60
drwnSegImageStdPixelFeatures * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnSegImagePixelFeatures.h:105
static bool INCLUDE_LBP
flag to include LBP features
Definition: drwnSegImagePixelFeatures.h:90
Interface for generating per-pixel features for a drwnSegImageInstance object.
Definition: drwnSegImagePixelFeatures.h:49
static bool INCLUDE_ROWCOLAGG
flag to include row and column aggregate features
Definition: drwnSegImagePixelFeatures.h:91
drwnFilterBankResponse _filters
pixel filter responses
Definition: drwnSegImagePixelFeatures.h:97
int numFeatures() const
return feature vector size
Definition: drwnSegImagePixelFeatures.h:169
Standard per-pixel filterbank features with option to read auxiliary features from a file...
Definition: drwnSegImagePixelFeatures.h:83
static bool INCLUDE_RGB
flag to include RGB colour features
Definition: drwnSegImagePixelFeatures.h:88
interface for cloning object (i.e., virtual copy constructor)
Definition: drwnInterfaces.h:36
static double FILTER_BANDWIDTH
bandwidth for filter features
Definition: drwnSegImagePixelFeatures.h:86
vector< vector< double > > _features
cached loaded features
Definition: drwnSegImagePixelFeatures.h:127
string featuresDir
directory containing feature files
Definition: drwnSegImagePixelFeatures.h:123
drwnSegImagePixelFeatures * clone() const =0
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
int _instanceHeight
width of the cached instance
Definition: drwnSegImagePixelFeatures.h:53
static int FEATURE_GRID_SPACING
cell size for pixel features
Definition: drwnSegImagePixelFeatures.h:87
Pre-processed per-pixel features stored in files.
Definition: drwnSegImagePixelFeatures.h:121
static vector< string > AUX_FEATURE_EXT
auxiliary feature extensions
Definition: drwnSegImagePixelFeatures.h:94
vector< vector< double > > _auxFeatures
cached auxiliary features
Definition: drwnSegImagePixelFeatures.h:98
drwnSegImageCompositePixelFeatures * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnSegImagePixelFeatures.h:160
static bool INCLUDE_HOG
flag to include HOG features
Definition: drwnSegImagePixelFeatures.h:89