Applying color gradient on an image in Android

被刻印的时光 ゝ 提交于 2019-12-12 03:57:19

问题


I am trying to replicate the functionalities of QGIS software in an Android application. I want to apply a color gradient (Red to Green lut) on an image for further efficient analysis.

The image shown below is generated after applying the NDVI (Normalised Difference Vegetation Index) indicator on it. The value of NDVI ranges from -1 to +1.

The image shown below is generated after applying the color gradient on it. This image now can be analysed efficiently because it shows the plants as green and the ground as red.

I tried the following code in Android for the result where NDVI is the NDVI value ranging from -1 to +1. I have not added the code for finding out the maximum and minimum value of NDVI but for my image, minimum value of NDVI is 0.11 and maximum value of NDVI is 0.57:

for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                final int pixel1 = src1[i][j];
                final int pixel2 = src2[i][j];

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

                final double NDVI = (X / Y);

                R = (int) ((255 * NDVI) / maxNDVI);
                G = (int) (((255 * (maxNDVI - NDVI)) / maxNDVI));
                B = 0;

                pixels[i][j] = Color.argb((Color.alpha(pixel1)), R, G, B);
         }
}

But I am not getting the appropriate result. Kindly help me out with this.

来源:https://stackoverflow.com/questions/42083570/applying-color-gradient-on-an-image-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!