Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnSegImageInstance.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: drwnSegImageInstance.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 <iostream>
18 #include <fstream>
19 #include <iomanip>
20 #include <vector>
21 #include <list>
22 
23 #include "Eigen/Core"
24 
25 #include "drwnBase.h"
26 #include "drwnIO.h"
27 #include "drwnML.h"
28 
29 #include "drwnPixelNeighbourContrasts.h"
30 #include "drwnSuperpixelContainer.h"
31 #include "drwnSegImagePixelFeatures.h"
32 #include "drwnVisionUtils.h"
33 
34 using namespace std;
35 using namespace Eigen;
36 
37 // drwnSegImageInstance class ----------------------------------------------
46 
48  protected:
49  string _baseName;
50  cv::Mat _img;
51  cv::Mat _grayImg;
52  cv::Mat _softEdgeImg;
53 
54  public:
55  // cached pixel features
56  vector<vector<double> > unaries;
58 
59  // long range edges
60  vector<drwnWeightedPixelEdge> auxEdges;
61 
62  // superpixels and auxiliary data
64  vector<cv::Mat> auxiliaryData;
65 
66  // class labels
67  MatrixXi pixelLabels;
68 
69  public:
71  drwnSegImageInstance(const char *imgFilename, const char *baseName = NULL);
73  drwnSegImageInstance(const cv::Mat& img, const char *baseName = NULL);
77  virtual ~drwnSegImageInstance();
78 
80  inline const cv::Mat& image() const { return _img; }
82  inline const cv::Mat& greyImage() const { return _grayImg; }
84  inline const cv::Mat& edgeMap() const { return _softEdgeImg; }
86  inline const string &name() const { return _baseName; }
87 
89  inline int width() const { return _img.cols; }
91  inline int height() const { return _img.rows; }
93  inline int size() const { return (_img.cols * _img.rows); }
94  //void resize(int w, int h);
95 
97  inline int pixel2Indx(const cv::Point& p) const { return pixel2Indx(p.x, p.y); }
99  inline int pixel2Indx(int x, int y) const { return y * _img.cols + x; }
101  inline cv::Point indx2Pixel(int indx) const {
102  return cv::Point(indx % _img.cols, indx / _img.cols);
103  }
104 
106  void clearPixelFeatures();
108  inline void appendPixelFeatures() {
110  appendPixelFeatures(g);
111  }
113  void appendPixelFeatures(drwnSegImagePixelFeatures &featureGenerator);
114 
116  drwnSegImageInstance& operator=(const drwnSegImageInstance& instance);
117 
118  protected:
120  void initInstance();
121 };
vector< vector< double > > unaries
cached unary potentials or pixel feature vectors
Definition: drwnSegImageInstance.h:56
vector< cv::Mat > auxiliaryData
auxiliary data for certain models (future extensions)
Definition: drwnSegImageInstance.h:64
int width() const
returns the width of the image in pixels
Definition: drwnSegImageInstance.h:89
Encapsulates a single instance of an image for multi-class pixel labeling problems (i...
Definition: drwnSegImageInstance.h:47
int pixel2Indx(int x, int y) const
convert from image coordinates to pixel index
Definition: drwnSegImageInstance.h:99
int height() const
returns the height of the image in pixels
Definition: drwnSegImageInstance.h:91
int pixel2Indx(const cv::Point &p) const
convert from image coordinates to pixel index
Definition: drwnSegImageInstance.h:97
int size() const
returns the number of pixels in the image
Definition: drwnSegImageInstance.h:93
Holds multiple oversegmentations for a given image.
Definition: drwnSuperpixelContainer.h:91
const cv::Mat & image() const
returns the colour image
Definition: drwnSegImageInstance.h:80
const cv::Mat & edgeMap() const
returns the edge magnitude of the image
Definition: drwnSegImageInstance.h:84
Interface for generating per-pixel features for a drwnSegImageInstance object.
Definition: drwnSegImagePixelFeatures.h:49
Convenience class for holding pixel contrast weights.
Definition: drwnPixelNeighbourContrasts.h:30
MatrixXi pixelLabels
pixel labels (0 to K-1) and -1 for unknown
Definition: drwnSegImageInstance.h:67
vector< drwnWeightedPixelEdge > auxEdges
auxiliary (long range) edges
Definition: drwnSegImageInstance.h:60
Standard per-pixel filterbank features with option to read auxiliary features from a file...
Definition: drwnSegImagePixelFeatures.h:83
drwnPixelNeighbourContrasts contrast
neighborhood contrast for pairwise smoothness
Definition: drwnSegImageInstance.h:57
void appendPixelFeatures()
append standard pixel features to cached pixel feature vectors
Definition: drwnSegImageInstance.h:108
drwnSuperpixelContainer superpixels
superpixels for features or consistency terms
Definition: drwnSegImageInstance.h:63
const cv::Mat & greyImage() const
returns a greyscale version of the image
Definition: drwnSegImageInstance.h:82
string _baseName
image identifier
Definition: drwnSegImageInstance.h:49
cv::Mat _grayImg
1-channel greyscale image of the scene
Definition: drwnSegImageInstance.h:51
cv::Mat _img
3-channel RGB image of the scene
Definition: drwnSegImageInstance.h:50
const string & name() const
returns the name of the image (if available)
Definition: drwnSegImageInstance.h:86
cv::Mat _softEdgeImg
1-channel edgemap image of the scene
Definition: drwnSegImageInstance.h:52
Computer vision utility functions (not dependent on OpenCV functions, but may use OpenCV data structu...
cv::Point indx2Pixel(int indx) const
convert from pixel index to image coordinates
Definition: drwnSegImageInstance.h:101