title: Image Processing How to Apply gradient [-1 | 0 | 1 ] to RGB image
body: <p>I need to apply gradient operator to RGB bitmap image. It works for 8 bit image but having the difficulty in implementing same for 24 bit image. Here is my code. Can anyone see how 
  to correct the zorizontal gradient operation to RGB image.</p>
  
  <pre><code>if (iBitPerPixel == 24)  ////RGB 24 bits image
  {
  
      for(int i=0; i&lt;iHeight; i++)
      for(int j=1; j&lt;iWidth-4; j++)
      {
          //pImg_Gradient[i*Wp+j] = pImg[i*Wp+j+1] - pImg[i*Wp+j-1] ;
          int level = pImg[i*Wp+j*3+1] - pImg[i*Wp+j*3-1] ;
          pImg_Gradient[i*Wp+j*3] = level;
  
  
      //  pImg_Gradient[i*Wp+j*3] =  level;
      //  pImg_Gradient[i*Wp+j*3+1] = level;
      //  pImg_Gradient[i*Wp+j*3+2]= level;
      }
  
      for(int i=0; i&lt;iHeight; i++)
          for(int j=0; j&lt;iWidth; j++)
      {
          // Copy the convetred values to original image.
          pImg[i*Wp+j] = (BYTE) pImg_Gradient[i*Wp+j];
      }
          //delete pImg_Gradient;
  }
  </code></pre>