title: Extract Near-Infrared (NIR) channel from a JPEG image in Android
body: <p>I am a beginner in image processing in Android. I am trying to build an application in which I need to separate the color channels from an image and perform calculations on them. </p>
  
  <p>I have successfully extracted RGB channels from the image. I am using the code fragment given in these tutorials: <a href="https://xjaphx.wordpress.com/2011/06/21/image-processing-filter-color-channels/" rel="nofollow noreferrer">https://xjaphx.wordpress.com/2011/06/21/image-processing-filter-color-channels/</a></p>
  
  <p>Here is the code fragment:</p>
  
  <pre><code>public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) {
          int width = src.getWidth();
          int height = src.getHeight();
  
          Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
  
          int A, R, G, B;
          int pixel;
  
          for(int x = 0; x &lt; width; ++x) {
              for(int y = 0; y &lt; height; ++y) {
  
                  pixel = src.getPixel(x, y);
  
                  A = Color.alpha(pixel);
                  R = (int)(Color.red(pixel) * red);
                  G = (int)(Color.green(pixel) * green);
                  B = (int)(Color.blue(pixel) * blue);
  
                  bmOut.setPixel(x, y, Color.argb(A, R, G, B));
              }
          }
  
  
          return bmOut;
      }
  }
  </code></pre>
  
  <p>But I am unable to figure out the way to extract NIR channel from the image. My aim to extract this NIR channel is because I need to apply the NDVI (Normalised Difference Vegetation Index) indicator on the image for analysis. </p>
  
  <p>Also, in this piece of code, brute-force approach has been used by running multiple for loops. Thus, the program becomes really slow with the complexity being - O(width*height). What would be an efficient way for computation of these separate channels?</p>
  
  <p>Screen shot of image properties:</p>
  
  <p><a href="https://i.stack.imgur.com/TWqvy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TWqvy.jpg" alt="Image"></a></p>
  
  <p><a href="https://i.stack.imgur.com/QZdn6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QZdn6.jpg" alt="Camera"></a></p>
  
  <p><a href="https://i.stack.imgur.com/URa3p.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/URa3p.jpg" alt="Advance photo"></a></p>
  
  <p>Kindly help me with this issue.</p>