segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
Functions
lbp Namespace Reference

Original code by philipp <bytefish[at]gmx[dot]de> More...

Functions

template<typename _Tp >
void histogram_ (const cv::Mat &src, cv::Mat &hist, int numPatterns)
 Original code by philipp <bytefish[at]gmx[dot]de> More...
 
template<typename _Tp >
double chi_square_ (const cv::Mat &histogram0, const cv::Mat &histogram1)
 
void spatial_histogram (const cv::Mat &src, cv::Mat &spatialhist, int numPatterns, const cv::Size &window, int overlap=0)
 
void spatial_histogram (const cv::Mat &src, cv::Mat &spatialhist, int numPatterns, int gridx=8, int gridy=8, int overlap=0)
 
void histogram (const cv::Mat &src, cv::Mat &hist, int numPatterns)
 
double chi_square (const cv::Mat &histogram0, const cv::Mat &histogram1)
 
cv::Mat histogram (const cv::Mat &src, int numPatterns)
 
cv::Mat spatial_histogram (const cv::Mat &src, int numPatterns, const cv::Size &window, int overlap=0)
 
cv::Mat spatial_histogram (const cv::Mat &src, int numPatterns, int gridx=8, int gridy=8, int overlap=0)
 
template<typename _Tp >
void OLBP_ (const cv::Mat &src, cv::Mat &dst)
 Original code by philipp <bytefish[at]gmx[dot]de> More...
 
template<typename _Tp >
void ELBP_ (const cv::Mat &src, cv::Mat &dst, int radius=1, int neighbors=8)
 
template<typename _Tp >
void VARLBP_ (const cv::Mat &src, cv::Mat &dst, int radius=1, int neighbors=8)
 
void OLBP (const cv::Mat &src, cv::Mat &dst)
 
void ELBP (const cv::Mat &src, cv::Mat &dst, int radius=1, int neighbors=8)
 
void VARLBP (const cv::Mat &src, cv::Mat &dst, int radius=1, int neighbors=8)
 
cv::Mat OLBP (const cv::Mat &src)
 
cv::Mat ELBP (const cv::Mat &src, int radius=1, int neighbors=8)
 
cv::Mat VARLBP (const cv::Mat &src, int radius=1, int neighbors=8)
 

Detailed Description

Original code by philipp <bytefish[at]gmx[dot]de>

Function Documentation

◆ histogram_()

template<typename _Tp >
void lbp::histogram_ ( const cv::Mat &  src,
cv::Mat &  hist,
int  numPatterns 
)

Original code by philipp <bytefish[at]gmx[dot]de>

Definition at line 28 of file histogram.cpp.

28  {
29  hist = cv::Mat::zeros(1, numPatterns, CV_32SC1);
30  for(int i = 0; i < src.rows; i++) {
31  for(int j = 0; j < src.cols; j++) {
32  int bin = src.at<_Tp>(i,j);
33  hist.at<int>(0,bin) += 1;
34  }
35  }
36 }

◆ OLBP_()

template<typename _Tp >
void lbp::OLBP_ ( const cv::Mat &  src,
cv::Mat &  dst 
)

Original code by philipp <bytefish[at]gmx[dot]de>

Definition at line 27 of file lbp.cpp.

27  {
28 
29  dst = cv::Mat::zeros(src.rows-2, src.cols-2, CV_8UC1);
30  for(int i=1;i<src.rows-1;i++) {
31  for(int j=1;j<src.cols-1;j++) {
32  _Tp center = src.at<_Tp>(i,j);
33  unsigned char code = 0;
34  code |= (src.at<_Tp>(i-1,j-1) > center) << 7;
35  code |= (src.at<_Tp>(i-1,j) > center) << 6;
36  code |= (src.at<_Tp>(i-1,j+1) > center) << 5;
37  code |= (src.at<_Tp>(i,j+1) > center) << 4;
38  code |= (src.at<_Tp>(i+1,j+1) > center) << 3;
39  code |= (src.at<_Tp>(i+1,j) > center) << 2;
40  code |= (src.at<_Tp>(i+1,j-1) > center) << 1;
41  code |= (src.at<_Tp>(i,j-1) > center) << 0;
42  dst.at<unsigned char>(i-1,j-1) = code;
43  }
44  }
45 }

◆ VARLBP_()

template<typename _Tp >
void lbp::VARLBP_ ( const cv::Mat &  src,
cv::Mat &  dst,
int  radius = 1,
int  neighbors = 8 
)

result

Definition at line 83 of file lbp.cpp.

83  {
84 
85  std::max(std::min(neighbors,31),1); // set bounds
86  dst = cv::Mat::zeros(src.rows-2*radius, src.cols-2*radius, CV_32FC1);
87  // allocate some memory for temporary on-line variance calculations
88  cv::Mat _mean = cv::Mat::zeros(src.rows, src.cols, CV_32FC1);
89  cv::Mat _delta = cv::Mat::zeros(src.rows, src.cols, CV_32FC1);
90  cv::Mat _m2 = cv::Mat::zeros(src.rows, src.cols, CV_32FC1);
91  for(int n=0; n<neighbors; n++) {
92  // sample points
93  float x = static_cast<float>(radius) * cos(2.0*M_PI*n/static_cast<float>(neighbors));
94  float y = static_cast<float>(radius) * -sin(2.0*M_PI*n/static_cast<float>(neighbors));
95  // relative indices
96  int fx = static_cast<int>(floor(x));
97  int fy = static_cast<int>(floor(y));
98  int cx = static_cast<int>(ceil(x));
99  int cy = static_cast<int>(ceil(y));
100  // fractional part
101  float ty = y - fy;
102  float tx = x - fx;
103  // set interpolation weights
104  float w1 = (1 - tx) * (1 - ty);
105  float w2 = tx * (1 - ty);
106  float w3 = (1 - tx) * ty;
107  float w4 = tx * ty;
108  // iterate through your data
109  for(int i=radius; i < src.rows-radius;i++) {
110  for(int j=radius;j < src.cols-radius;j++) {
111  float t = w1*src.at<_Tp>(i+fy,j+fx) + w2*src.at<_Tp>(i+fy,j+cx) + w3*src.at<_Tp>(i+cy,j+fx) + w4*src.at<_Tp>(i+cy,j+cx);
112  _delta.at<float>(i,j) = t - _mean.at<float>(i,j);
113  _mean.at<float>(i,j) = (_mean.at<float>(i,j) + (_delta.at<float>(i,j) / (1.0*(n+1)))); // i am a bit paranoid
114  _m2.at<float>(i,j) = _m2.at<float>(i,j) + _delta.at<float>(i,j) * (t - _mean.at<float>(i,j));
115  }
116  }
117  }
118  // calculate result
119  for(int i = radius; i < src.rows-radius; i++) {
120  for(int j = radius; j < src.cols-radius; j++) {
121  dst.at<float>(i-radius, j-radius) = _m2.at<float>(i,j) / (1.0*(neighbors-1));
122  }
123  }
124 }