Ask Your Question

Revision history [back]

yes it's possible to calculate a ratio by pixel using opencv

      Mat bgr;

     ....
      vector<Mat> p;

       split(bgr, p);

        Mat num;
        subtract(p[0], p[2], num,Mat(),CV_32F);
        Mat den;
        add(p[0], p[2], den, Mat(),CV_32F);
        Mat ratio;
        divide(num, den, ratio,CV_32F); // and hope that den is never equal to 0. you can add 0.01 to den

Now about NDVI : p[0] is NIR and p[2] is visible but is it true for your sensors?

yes it's possible to calculate a ratio by pixel using opencv

      Mat bgr;

     ....
      vector<Mat> p;

       split(bgr, p);

        Mat num;
        subtract(p[0], p[2], num,Mat(),CV_32F);
        Mat den;
        add(p[0], p[2], den, Mat(),CV_32F);
        Mat ratio;
        divide(num, den, ratio,CV_32F); // and hope that den is never equal to 0. you can add 0.01 to den

Now about NDVI : p[0] is NIR and p[2] is visible but is it true for your sensors?sensor?