Direct Graphical Models  v.1.7.0
Scale.cpp
1 #include "Scale.h"
2 
3 namespace DirectGraphicalModels { namespace fex
4 {
5 Mat CScale::get(const Mat &img, SqNeighbourhood nbhd)
6 {
7  int width = img.cols;
8  int height = img.rows;
9  int nChannels = img.channels();
10 
11  Mat res(img.size(), img.type());
12  vec_mat_t vChannels;
13  split(img, vChannels);
14 
15  Mat integralImg;
16  for (byte c = 0; c < nChannels; c++) {
17  integral(vChannels[c], integralImg);
18 
19  for (int y = 0; y < height; y++) {
20  int y0 = MAX(0, y - nbhd.upperGap);
21  int y1 = MIN(y + nbhd.lowerGap, height - 1);
22  byte *pRes = res.ptr<byte>(y);
23  int *pI0 = integralImg.ptr<int>(y0);
24  int *pI1 = integralImg.ptr<int>(y1 + 1);
25  for (int x = 0; x < width; x++) {
26  int x0 = MAX(0, x - nbhd.leftGap);
27  int x1 = MIN(x + nbhd.rightGap, width - 1);
28  int S = (x1 - x0 + 1) * (y1 - y0 + 1);
29  float med = static_cast<float>(pI1[x1 + 1] - pI1[x0] - pI0[x1 + 1] + pI0[x0]) / S;
30  pRes[nChannels * x + c] = static_cast<byte>(med + 0.5f);
31  } // x
32  } // y
33  } // c
34 
35  return res;
36 }
37 } }
int rightGap
Distance from the base point to the neighborhood&#39;s right boundary.
int leftGap
Distance from the base point to the neighborhood&#39;s left boundary.
int lowerGap
Distance from the base point to the neighborhood&#39;s lower boundary.
virtual Mat get(void) const
Extracts and returns the required feature.
Definition: Scale.h:26
int upperGap
Distance from the base point to the neighborhood&#39;s upper boundary.