Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnMultiSegConfig.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-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnMultiSegConfig.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 <list>
18 #include <map>
19 
20 #include "Eigen/Core"
21 
22 #include "cv.h"
23 
24 #include "drwnBase.h"
25 
26 using namespace std;
27 
28 // drwnMultiSegConfig -------------------------------------------------------
35 
37  protected:
38  string _baseDir;
39  string _imgDir;
40  string _lblDir;
41  string _segDir;
42  string _cacheDir;
43  string _modelsDir;
44  string _outputDir;
45  string _imgExt;
46  string _lblExt;
47  string _segExt;
48  bool _bUseCache;
50 
51  public:
54 
55  // options i/o
56  void readConfiguration(drwnXMLNode& node);
57  void setConfiguration(const char *name, const char *value) {
58  drwnProperties::setProperty(drwnProperties::findProperty(name), value);
59  }
60 
61  void usage(std::ostream& os) const;
62 
63  // utility functions
66  string filebase(const char *dirKey, const char *baseName);
69  string filebase(const char *dirKey, const string& baseName);
72  string filename(const char *dirKey, const char *baseName, const char *extKey);
75  string filename(const char *dirKey, const string& baseName, const char *extKey);
76 };
77 
78 extern drwnMultiSegConfig gMultiSegConfig;
79 
80 // drwnStandardMultiSegRegionDatasets ----------------------------------------
83 
84 typedef enum _drwnStandardMultiSegRegionDatasets {
85  DRWN_DS_FGBG,
86  DRWN_DS_MSRC,
87  DRWN_DS_STANFORD,
88  DRWN_DS_PASCALVOC
89 } drwnStandardMultiSegRegionDatasets;
90 
91 // drwnMultiSegRegionDefinitions ---------------------------------------------
125 
127  protected:
128  map<int, int> _keys;
129  vector<unsigned int> _colors;
130  vector<string> _names;
131 
132  public:
136  drwnMultiSegRegionDefinitions(const char *filename);
138 
139  // i/o
141  void clear();
143  void read(const char *filename);
145  void read(drwnXMLNode& root);
146 
148  bool empty() const { return _colors.empty(); }
150  int size() const { return (int)_colors.size(); }
152  int maxKey() const;
153 
155  set<int> keys() const;
157  string name(int key) const;
159  unsigned int color(int key) const;
160 
162  static unsigned char red(unsigned int c) {
163  return ((c >> 16) & 0xff);
164  }
166  static unsigned char green(unsigned int c) {
167  return ((c >> 8) & 0xff);
168  }
170  static unsigned char blue(unsigned int c) {
171  return (c & 0xff);
172  }
174  static unsigned int rgb(unsigned char r, unsigned char g, unsigned char b) {
175  return ((unsigned int)(r << 16) | (unsigned int)(g << 8) | (unsigned int)b);
176  }
177 
179  virtual void initializeForDataset(const drwnStandardMultiSegRegionDatasets& dataset);
180 
182  MatrixXi convertImageToLabels(const cv::Mat& img) const;
184  MatrixXi convertImageToLabels(const char *filename) const;
185 
187  MatrixXi loadLabelFile(const char *filename) const;
188 
189  // operators
191  unsigned int& operator[](int key);
192 
193  protected:
195  virtual void initDefaultRegions();
196 };
197 
198 extern drwnMultiSegRegionDefinitions gMultiSegRegionDefs;
static unsigned char green(unsigned int c)
converts from 32-bit colour to 8-bit green
Definition: drwnMultiSegConfig.h:166
static unsigned int rgb(unsigned char r, unsigned char g, unsigned char b)
converts 8-bit red, green and blue into 32-bit colour
Definition: drwnMultiSegConfig.h:174
string _segDir
directory containing over-segmentations (relative to _baseDir)
Definition: drwnMultiSegConfig.h:41
Provides an abstract interface for dynamic properties.
Definition: drwnProperties.h:338
string _cacheDir
directory to store pre-computed features (relative to _baseDir)
Definition: drwnMultiSegConfig.h:42
string _imgDir
directory containing images (relative to _baseDir)
Definition: drwnMultiSegConfig.h:39
bool _bUseCache
set true to store features in the _cacheDir
Definition: drwnMultiSegConfig.h:48
bool _bCompressedCache
set true to compress cached data
Definition: drwnMultiSegConfig.h:49
void setConfiguration(const char *name, const char *value)
set individual configurable parameter
Definition: drwnMultiSegConfig.h:57
string _segExt
file extension for over-segmentations (drwnSuperpixelContainer)
Definition: drwnMultiSegConfig.h:47
static unsigned char red(unsigned int c)
converts from 32-bit colour to 8-bit red
Definition: drwnMultiSegConfig.h:162
Interface for a configurable module.
Definition: drwnConfigManager.h:35
string _imgExt
file extension of images
Definition: drwnMultiSegConfig.h:45
string _outputDir
directory to write results (relative to _baseDir)
Definition: drwnMultiSegConfig.h:44
string _lblDir
directory conatining labels (relative to _baseDir)
Definition: drwnMultiSegConfig.h:40
int size() const
returns the number of defined regions
Definition: drwnMultiSegConfig.h:150
Manages configuration settings for multiple image segmentation.
Definition: drwnMultiSegConfig.h:36
bool empty() const
returns true if no regions have been definied
Definition: drwnMultiSegConfig.h:148
vector< string > _names
name of class for i-th key
Definition: drwnMultiSegConfig.h:130
string _lblExt
file extension of image
Definition: drwnMultiSegConfig.h:46
Provides a mechanism for mapping region IDs to colours and class names. Can be initialized from an XM...
Definition: drwnMultiSegConfig.h:126
map< int, int > _keys
mapping from keys to colour and name index
Definition: drwnMultiSegConfig.h:128
string _baseDir
base directory for data, models and results
Definition: drwnMultiSegConfig.h:38
static unsigned char blue(unsigned int c)
converts from 32-bit colour to 8-bit blue
Definition: drwnMultiSegConfig.h:170
vector< unsigned int > _colors
colour for i-th key
Definition: drwnMultiSegConfig.h:129
string _modelsDir
directory to read and write model files (relative to _baseDir)
Definition: drwnMultiSegConfig.h:43