Direct Graphical Models  v.1.7.0
Intensity.cpp
1 #include "Intensity.h"
2 #include "macroses.h"
3 
4 namespace DirectGraphicalModels { namespace fex
5 {
6 Mat CIntensity::get(const Mat &img, cv::Scalar weight)
7 {
8  DGM_ASSERT_MSG(img.channels() == 3, "Input image has %d channel(s), but must have 3.", img.channels());
9 
10  // OpenCV function addWeighted() has a bug.
11  Mat res(img.size(), CV_8UC1);
12  for (int y = 0; y < img.rows; y++) {
13  const byte *pImg = img.ptr<byte>(y);
14  byte *pRes = res.ptr<byte>(y);
15  for (int x = 0; x < img.cols; x++) {
16  double sum = 0;
17  for (int c = 0; c < 3; c++)
18  sum += weight.val[c] * pImg[3 * x + c];
19  pRes[x] = static_cast<byte> (MIN(255, MAX(0, sum + 0.5f)));
20  } // x
21  } // y
22 
23  return res;
24 }
25 } }
virtual Mat get(void) const
Extracts and returns the required feature.
Definition: Intensity.h:24