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.