2 #include "LinearMapper.h" 13 if (img.channels() != 1) cvtColor(img, I, cv::ColorConversionCodes::COLOR_RGB2GRAY);
16 Mat res(img.size(), CV_8UC1);
18 integral(I, integralImg);
20 for (
int y = 0; y < height; y++) {
22 int y1 = MIN(y + nbhd.
lowerGap, height -1);
23 byte *pRes = res.ptr<byte>(y);
24 int *pI0 = integralImg.ptr<
int>(y0);
25 int *pI1 = integralImg.ptr<
int>(y1 + 1);
26 for (
int x = 0; x < width; x++) {
27 int x0 = MAX(0, x - nbhd.
leftGap);
28 int x1 = MIN(x + nbhd.
rightGap, width - 1);
29 int S = (x1 - x0 + 1) * (y1 - y0 + 1);
30 float med =
static_cast<float>(pI1[x1 + 1] - pI1[x0] - pI0[x1 + 1] + pI0[x0]) / S;
32 for (
int j = y0; j <= y1; j++) {
33 byte *pImg = I.ptr<byte>(j);
34 for (
int i = x0; i <= x1; i++) {
35 float dif =
static_cast<float>(pImg[i]) - med;
39 float val = sqrtf(Sum / S);
40 pRes[x] = linear_mapper<byte>(val, 0, 100);
int rightGap
Distance from the base point to the neighborhood's right boundary.
int leftGap
Distance from the base point to the neighborhood's left boundary.
int lowerGap
Distance from the base point to the neighborhood's lower boundary.
int upperGap
Distance from the base point to the neighborhood's upper boundary.
Square neighborhood structure.
virtual Mat get(void) const
Extracts and returns the required feature.