KSquare Utilities
FeatureVectorProducer.h
Go to the documentation of this file.
1 #if !defined(_FEATUREVECTORPRODUCER_)
2 #define _FEATUREVECTORPRODUCER_
3 
4 /**
5  *@class KKMLL::FeatureVectorProducer
6  *@brief A abstract class that is meant to compute a FeatureVector from a source image.
7  *@details Applications that want to utilize this library will either use one of the
8  *provided "FeatureVectorProducer" derived classes or supply their own. This class will
9  *be responsible for computing a FeatureVector from a supplied Image.
10  *
11  *Each FeatureVectorProducer derived class will need to have a unique name that will be supplied when
12  *constructed. This name will be used later when it is required to locate the appropriate
13  *FeatureVectorProducer to utilize.
14  *@see FeatureVectorList
15  *@see PostLarvaeFV
16  *@see FeatureFileIO
17  */
18 
19 
20 #include "RunLog.h"
21 #include "Raster.h"
22 using namespace KKB;
23 
24 
25 
26 namespace KKMLL
27 {
28 
29 #if !defined(_FeatureVector_Defined_)
30  class FeatureVector;
32 #endif
33 
34 
35 #if !defined(_FeatureVectorList_Defined_)
36  class FeatureVectorList;
38 #endif
39 
40 
41 #if !defined(_FileDesc_Defined_)
42  class FileDesc;
43  typedef FileDesc* FileDescPtr;
44  typedef FileDesc* const FileDescConstPtr;
45 #endif
46 
47 
48 #if !defined(_MLClass_Defined_)
49  class MLClass;
50  typedef MLClass* MLClassPtr;
51 #endif
52 
53 
54 #if !defined(_FactoryFVProducer_Defined_)
55  class FactoryFVProducer;
57 #endif
58 
59 
61  {
62  public:
64 
65  FeatureVectorProducer (const KKStr& _name,
66  FactoryFVProducerPtr _factory /**< Pointer to factory that instantiated this instance. */
67  );
68 
69  virtual ~FeatureVectorProducer ();
70 
71 
72  /**
73  *@brief Compute a FeatureVector for the supplied 'image'.
74  *@param[in] image
75  *@param[in] knownClass The class label that will be assigned to this Feature vector.
76  *@param[in,out] intermediateImages If not NULL will save a copy of the intermediate images created during Feature Computation; the call will own the list and its contents.
77  *@param[in] priorReductionFactor The reduction that was done to the image prior to calling this routine; if no size change was made then set this field to 1.0. The
78  * FeaureVector computation routines will use this field to adjust SizeDependent features appropriately. the value of this parameter represents
79  * the number of pixels that were reduced to 1 pixel. A value of 3 indicates (3 x 3) pixels were reduced to 1 pixel.
80  *@param[in] log Logging file.
81  *@returns The resultant Feature vector computed.
82  */
83  virtual FeatureVectorPtr ComputeFeatureVector (const Raster& image,
84  const MLClassPtr knownClass,
85  RasterListPtr intermediateImages,
86  float priorReductionFactor,
87  RunLog& runLog
88  ) = 0;
89 
90 
91  /**
92  *@brief Compute a FeatureVector from the image file specified by 'fileName'
93  *@param[in] image
94  *@param[in] knownClass The class label that will be assigned to this Feature vector.
95  *@param[in,out] intermediateImages If not NULL will save a copy of the intermediate images created during Feature Computation; the call will own the list and its contents.
96  *@param[in] log Logging file.
97  *@returns The resultant Feature vector computed.
98  */
99  virtual FeatureVectorPtr ComputeFeatureVectorFromImage (const KKStr& fileName,
100  const MLClassPtr knownClass,
101  RasterListPtr intermediateImages,
102  RunLog& runLog
103  );
104 
105 
106 
107  /** @brief Returns the 'type_info' of the FeatureVector that this instance of 'FeatureVectorProducer' creates. */
108  virtual const type_info* FeatureVectorTypeId () const = 0;
109 
110 
111  /**
112  *@brief Returns the 'type_info' of the FeatureVectorList derived class that can contain instances in 'FeatureVector'
113  * instances created by this producer.
114  */
115  virtual const type_info* FeatureVectorListTypeId () const = 0;
116 
117 
118  virtual kkint16 Version () const = 0; /**< The version number of the FeatureVector that is going to be computed. */
119 
120 
121  /** @brief Returns pointer to factory that instantiated this instance */
122  FactoryFVProducerPtr Factory () const {return factory;}
123 
124 
125  /**
126  *@brief Returns back a "FileDesc" instance that describes the features that this instance of 'FeatureVectorProducer' creates.
127  * The class derived form this class is responsible for creating the FileDesc instance. When this method is called if "fileDesc"
128  * equals NULL then will call "DefineFileDesc", which is a pure virtual method that will be implemented by the derived class, to
129  * instantiate a new instance.
130  */
131  FileDescConstPtr FileDesc () const;
132 
133 
134  /** @brief Returns a kkint16 description of the FeatureVector which can be used as part/all of a File or Directory name. */
135  const KKStr& Name () const {return name;};
136 
137 
138  // Feature description related methods.
139  kkuint32 FeatureCount () const;
140 
141 
142  const KKStr& FeatureName (kkuint32 fieldNum) const;
143 
144 
145  kkuint32 MaxNumOfFeatures () {return FeatureCount ();} /**< Same as FeatureCount */
146 
147 
148  /**
149  *@brief Manufactures a instance of a derived 'FeatureVectorList' class that is appropriate for containing instances
150  *of FeatureVectors by this FeatureVectorProducer.
151  */
153  RunLog& runLog
154  ) const = 0;
155 
156 
157  protected:
158  virtual FileDescPtr DefineFileDesc () const = 0;
159 
160  private:
161  FactoryFVProducerPtr factory;
162  mutable FileDescPtr fileDesc;
163  KKStr name;
164 
165  static bool atExitDefined;
166  }; /* FeatureVectorProducer */
167 
169 
170 #define _FeatureVectorProducer_Defined_
171 
172 } /* KKMLL */
173 
174 #endif
#define _FactoryFVProducer_Defined_
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
virtual const type_info * FeatureVectorTypeId() const =0
Returns the &#39;type_info&#39; of the FeatureVector that this instance of &#39;FeatureVectorProducer&#39; creates...
#define _MLClass_Defined_
Definition: MLClass.h:219
virtual FeatureVectorListPtr ManufacturFeatureVectorList(bool owner, RunLog &runLog) const =0
Manufactures a instance of a derived &#39;FeatureVectorList&#39; class that is appropriate for containing ins...
FeatureVector * FeatureVectorPtr
Definition: Model.h:44
virtual kkint16 Version() const =0
#define _FeatureVector_Defined_
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
FileDescConstPtr FileDesc() const
Returns back a "FileDesc" instance that describes the features that this instance of &#39;FeatureVectorPr...
virtual FileDescPtr DefineFileDesc() const =0
#define _FileDesc_Defined_
Definition: FileDesc.h:309
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
const KKStr & FeatureName(kkuint32 fieldNum) const
KKTHread * KKTHreadPtr
RasterList * RasterListPtr
Definition: Raster.h:75
virtual const type_info * FeatureVectorListTypeId() const =0
Returns the &#39;type_info&#39; of the FeatureVectorList derived class that can contain instances in &#39;Feature...
#define _FeatureVectorList_Defined_
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
virtual FeatureVectorPtr ComputeFeatureVector(const Raster &image, const MLClassPtr knownClass, RasterListPtr intermediateImages, float priorReductionFactor, RunLog &runLog)=0
Compute a FeatureVector for the supplied &#39;image&#39;.
virtual FeatureVectorPtr ComputeFeatureVectorFromImage(const KKStr &fileName, const MLClassPtr knownClass, RasterListPtr intermediateImages, RunLog &runLog)
Compute a FeatureVector from the image file specified by &#39;fileName&#39;.
FileDesc * FileDescPtr
FactoryFVProducerPtr Factory() const
Returns pointer to factory that instantiated this instance.
const KKStr & Name() const
Returns a kkint16 description of the FeatureVector which can be used as part/all of a File or Directo...
FeatureVectorProducer * FeatureVectorProducerPtr
FeatureVectorProducer(const KKStr &_name, FactoryFVProducerPtr _factory)
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
FeatureVectorProducer * FeatureVectorProducerPtr
FeatureVectorList * FeatureVectorListPtr
Definition: Model.h:46
A abstract class that is meant to compute a FeatureVector from a source image.
FactoryFVProducer * FactoryFVProducerPtr
Definition: Model.h:75