Android中NDVI的不正确计算

时间:2017-02-15 11:57:17

标签: android image image-processing camera

我是图像处理新手。我正在尝试在Android的农业农场图像上实现NDVI索引。但是,我无法得到理想的结果。

原始图片:

enter image description here

我正在使用此代码段来计算NDVI:

public int[][] applyNDVI(int[][] src1, int[][] src2) {

        final int pixels[][] = new int[width][height];



        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                //src1 is the image in red channel and src2 is the image in the blue channel.
                final int pixel1 = src1[i][j];
                final int pixel2 = src2[i][j];

                final double X = (pixel2 - pixel1);
                final double Y = (pixel2 + pixel1);

                double Z = (X / Y);

                //double Z = ((double)pixel1/(double)pixel2);

                int NDVI;
                NDVI = (int) (Z * 255);


                pixels[i][j] = Color.argb(Color.alpha(pixel1), NDVI, NDVI, NDVI);
       }
    }
    return pixels;
}

此代码段给出了此输出:

enter image description here

根据我所读到的NDVI,与贫瘠/干燥地面(<0.2)相比,植被具有更高的NDVI值(在0.2和0.9之间)。因此,植物应为浅灰色,NDVI图像中的地面应为深灰色。但我得到了正好相反的形象。

当我使用不同的NDVI公式时,即NDVI = Red Channel / Blue Channel`i.e。

double Z =((double)pixel1 /(double)pixel2);`

这个公式给了我想要的输出(几乎)。

enter image description here

所以,我无法理解这种差异。此外,我想知道NDVI公式是否取决于所使用的相机和拍摄的图像?或者NDVI的公式是否通用?如果它是通用的,我在哪里出错,为什么我不能得到所需的输出。任何形式的帮助都将深受赞赏。

0 个答案:

没有答案