2 #include "LinearMapper.h" 9 DGM_ASSERT_MSG(img.channels() == 3,
"Input image has %d channel(s), but must have 3.", img.channels());
10 Mat res(img.size(), CV_8UC1);
12 split(img, vChannels);
14 for (
int y = 0; y < res.rows; y++) {
15 byte *pRes = res.ptr<byte>(y);
16 byte *pR = vChannels.at(2).ptr<byte>(y);
17 byte *pG = vChannels.at(1).ptr<byte>(y);
18 byte *pB = vChannels.at(0).ptr<byte>(y);
19 for (
int x = 0; x < res.cols; x++) {
20 float nir =
static_cast<float>(pR[x]);
21 float vis = 0.5f * (
static_cast<float>(pG[x]) + static_cast<float>(pB[x]));
22 float ndvi = (nir + vis > 0) ? (nir - vis) / (nir + vis) : 0;
24 pRes[x] = two_linear_mapper<byte>(ndvi, -1.0f, 1.0f, 0.0f, midPoint);
virtual Mat get(void) const
Extracts and returns the required feature.