Direct Graphical Models  v.1.7.0
CommonFeatureExtractor.cpp
1 #include "CommonFeatureExtractor.h"
2 
3 namespace DirectGraphicalModels { namespace fex
4 {
6 {
7  Mat res;
8  bitwise_not(m_img, res);
9  return CCommonFeatureExtractor(res);
10 }
11 
13 {
14  Mat res;
15  R = 2 * R + 1;
16  GaussianBlur(m_img, res, cv::Size(R, R), 0.0, 0.0, BORDER_REFLECT);
17  return CCommonFeatureExtractor(res);
18 }
19 
21 {
22  DGM_ASSERT_MSG(m_img.depth() == CV_8U, "The source image must have 8-bit / channel depth");
23  Mat res;
24  vec_mat_t vChannels;
25  split(m_img, vChannels);
26 #ifdef ENABLE_PPL
27  concurrency::parallel_for_each(vChannels.begin(), vChannels.end(), [](Mat &c) {
28 #else
29  for (Mat &c : vChannels) {
30 #endif
31  double minVal, maxVal;
32  minMaxLoc(c, &minVal, &maxVal);
33  double k = (maxVal > minVal) ? k = 255.0 / (maxVal - minVal) : 1.0;
34  c.convertTo(c, c.type(), k, -minVal * k);
35  }
36 #ifdef ENABLE_PPL
37  );
38 #endif
39  merge(vChannels, res);
40  return CCommonFeatureExtractor(res);
41 }
42 
44 {
45  // Converting to one channel image
46  Mat res;
47  if (m_img.channels() != 1) cvtColor(m_img, res, cv::ColorConversionCodes::COLOR_RGB2GRAY);
48  else m_img.copyTo(res);
49 
50  for (int y = 0; y < res.rows; y++) {
51  byte *pRes = res.ptr<byte>(y);
52  for (int x = 0; x < res.cols; x++)
53  pRes[x] = (pRes[x] > threshold) ? 225 : 0;
54  } // y
55 
56  return CCommonFeatureExtractor(res);
57 }
58 
60 {
61  DGM_ASSERT_MSG(channel < m_img.channels(), "The required channel %d does not exist in the %d-channel source image", channel, m_img.channels());
62  Mat res;
63  vec_mat_t vChannels;
64  split(m_img, vChannels);
65  vChannels.at(channel).copyTo(res);
66  vChannels.clear();
67  return CCommonFeatureExtractor(res);
68 }
69 } }
CCommonFeatureExtractor getChannel(int channel) const
Extracts one channel from the source image.
CCommonFeatureExtractor blur(int R=2) const
Performs Gaussian blurring of the source image.
CCommonFeatureExtractor autoContrast(void) const
Performs histogram stretching of the source image.
CCommonFeatureExtractor invert(void) const
Inverts the source image.
CCommonFeatureExtractor thresholding(byte threshold) const
Performs thresholding on the source image.
Common class, which unites feature extraction algorithms.
const Mat m_img
Container for the image, from which the features are to be extracted.