2 #include "LinearMapper.h" 9 DGM_ASSERT(mid <= GRADIENT_MAX_VALUE);
14 if (img.channels() != 1) cvtColor(img, I, cv::ColorConversionCodes::COLOR_RGB2GRAY);
22 Mat res(img.size(), CV_8UC1);
23 for(
int y = 0; y < img.rows; y++) {
24 float *pIx = Ix.ptr<
float>(y);
25 float *pIy = Iy.ptr<
float>(y);
26 for(
int x = 0; x < img.cols; x++) {
27 float val = sqrtf(pIx[x]*pIx[x] + pIy[x]*pIy[x]);
28 res.at<byte>(y,x) = two_linear_mapper<byte>(val, 0, GRADIENT_MAX_VALUE, mid, 255);
37 DGM_ASSERT(img.channels() == 1);
39 Mat res(img.size(), CV_32FC1); res.setTo(0);
40 for(
int y = 0; y < res.rows; y++) {
41 const byte *pImg = img.ptr<byte>(y);
42 float *pRes = res.ptr<
float>(y);
43 for(
int x = 1; x < res.cols - 1; x++)
44 pRes[x] = 0.5f * (static_cast<float>(pImg[x + 1]) -
static_cast<float>(pImg[x - 1]));
51 DGM_ASSERT(img.channels() == 1);
53 Mat res(img.size(), CV_32FC1); res.setTo(0);
54 for(
int y = 1; y < res.rows - 1; y++) {
55 const byte *pImgF = img.ptr<byte>(y + 1);
56 const byte *pImgB = img.ptr<byte>(y - 1);
57 float *pRes = res.ptr<
float>(y);
58 for(
int x = 0; x < res.cols; x++)
59 pRes[x] = 0.5f * (static_cast<float>(pImgF[x]) -
static_cast<float>(pImgB[x]));
virtual Mat get(void) const
Extracts and returns the required feature.
static Mat getDerivativeY(const Mat &img)
static Mat getDerivativeX(const Mat &img)