Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnVisionUtils.h
Go to the documentation of this file.
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: drwnVisionUtils.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 ** Jimmy Lin <JimmyLin@utexas.edu>
11 **
12 *****************************************************************************/
13 
21 #pragma once
22 
23 #include <cstdlib>
24 #include <cassert>
25 #include <vector>
26 
27 #include "Eigen/Core"
28 
29 #include "cv.h"
30 
31 #include "drwnBase.h"
32 #include "drwnIO.h"
33 
34 using namespace std;
35 using namespace Eigen;
36 
39  public:
40  double w;
41  cv::Point p;
42  cv::Point q;
43 
44  public:
45  drwnWeightedPixelEdge() : w(0.0), p(-1, -1), q(-1, -1) { /* do nothing */ };
46  drwnWeightedPixelEdge(const cv::Point& _p, const cv::Point& _q, double _w = 0.0) :
47  w(_w), p(_p), q(_q) { /* do nothing */ };
48  ~drwnWeightedPixelEdge() { /* do nothing */ };
49 
51  bool operator<(const drwnWeightedPixelEdge& e) const {
52  if (w < e.w) return true;
53  if (w > e.w) return false;
54  if (p.y < e.p.y) return true;
55  if (p.y > e.p.y) return false;
56  if (p.x < e.p.x) return true;
57  if (p.x > e.p.x) return false;
58  if (q.y < e.q.y) return true;
59  if (q.y > e.q.y) return false;
60  return (q.x < e.q.x);
61  };
62 };
63 
65 inline double drwnPyramidScale(int lambda) {
66  return exp(-1.0 * log(2.0) / (double)lambda);
67 }
68 
70 cv::Rect drwnTransformROI(const cv::Rect& roi, const cv::Size& srcSize, const cv::Size& dstSize);
71 
75 void drwnLoadPixelLabels(cv::Mat& pixelLabels, const char *filename);
76 
81 void drwnLoadPixelLabels(cv::Mat& pixelLabels, const char *filename, int numLabels);
82 
86 void drwnLoadPixelLabels(MatrixXi &pixelLabels, const char *filename,
87  int numLabels = DRWN_INT_MAX);
88 
93 int drwnConnectedComponents(cv::Mat& segments, bool b8Connected = false);
95 int drwnConnectedComponents(MatrixXi& segments, bool b8Connected = false);
96 
100 cv::Mat drwnFastSuperpixels(const cv::Mat& img, unsigned gridSize);
101 
105 cv::Mat drwnKMeansSegments(const cv::Mat& img, unsigned numCentroids);
106 
113 cv::Mat drwnSLICSuperpixels(const cv::Mat& img, unsigned nClusters,
114  double spatialWeight = 200.0, double threshold = 1.0e-3);
115 
118 void drwnMergeSuperpixels(const cv::Mat& img, cv::Mat& seg, unsigned maxSegs);
119 
124 std::vector<std::pair<cv::Mat, unsigned> > drwnLoadCIFAR(const string& filename,
125  unsigned headerBytes = 1, cv::Size sz = cv::Size(32, 32), unsigned nChannels = 3);
126 
void drwnMergeSuperpixels(const cv::Mat &img, cv::Mat &seg, unsigned maxSegs)
Merges small superpixels into neighbours until at most maxSegs remain.
Definition: drwnVisionUtils.cpp:617
cv::Rect drwnTransformROI(const cv::Rect &roi, const cv::Size &srcSize, const cv::Size &dstSize)
Maps a region of interest from one image scale to another.
Definition: drwnVisionUtils.cpp:34
int drwnConnectedComponents(cv::Mat &segments, bool b8Connected=false)
Finds connected components in an over-segmentation and renumbers superpixels contiguously from 0...
Definition: drwnVisionUtils.cpp:142
void drwnLoadPixelLabels(cv::Mat &pixelLabels, const char *filename)
Load an over-segmentation (superpixel image) or pixel labeling from a .png or .txt file...
Definition: drwnVisionUtils.cpp:45
cv::Point q
second pixel
Definition: drwnVisionUtils.h:42
double w
weight
Definition: drwnVisionUtils.h:40
Weighted undirected arc between pixels in an image.
Definition: drwnVisionUtils.h:38
cv::Mat drwnSLICSuperpixels(const cv::Mat &img, unsigned nClusters, double spatialWeight=200.0, double threshold=1.0e-3)
Generates an over-segmentation (superpixels) of an image based on the SLIC algorithm (Achanta et al...
Definition: drwnVisionUtils.cpp:472
cv::Mat drwnKMeansSegments(const cv::Mat &img, unsigned numCentroids)
Generates an over-segmentation (superpixels) of an image as a set of disconnected regions...
Definition: drwnVisionUtils.cpp:408
cv::Point p
first pixel
Definition: drwnVisionUtils.h:41
bool operator<(const drwnWeightedPixelEdge &e) const
default comparison for sorting
Definition: drwnVisionUtils.h:51
double drwnPyramidScale(int lambda)
Image rescaling factor for lambda levels per octave.
Definition: drwnVisionUtils.h:65
std::vector< std::pair< cv::Mat, unsigned > > drwnLoadCIFAR(const string &filename, unsigned headerBytes=1, cv::Size sz=cv::Size(32, 32), unsigned nChannels=3)
Loads CIFAR-10, CIFAR-100 or similarly stored datasets, where images are stored in binary row-major o...
Definition: drwnVisionUtils.cpp:708
cv::Mat drwnFastSuperpixels(const cv::Mat &img, unsigned gridSize)
Generates an over-segmentation (superpixels) of an image. The parameter gridSize controls the number ...
Definition: drwnVisionUtils.cpp:300