图像运算(九)——逻辑反(NOT)

描述:逻辑反操作即反向操作,正如二进制图像中,黑变成白,白变成黑


input output

0                1

1                0


公式描述:O(i,j) = (2^n -1) - I(i,j) ,n表示该图像是n-bits


Code:

  /**    
   *apply_invert applies an inversion operator to an image
   *@param src_1d The source image as a pixel array
   *@param width width of the destination image in pixels
   *@param height height of the destination image in pixels
   *
   *@return A pixel array containing the inverted input image
   */


  public int [] apply_invert(int [] src_1d, int width, int height) {
    
    d_w = width;
    d_h = height;
    dest_1d = new int[d_w * d_h];
    int src_rgb;
    int result = 0; 
    
    
    for(int i=0;i<src_1d.length;i++){

      src_rgb = src_1d[i] & 0x000000ff;
      result = 255 - src_rgb;
      
      //Convert back to 32 bit integer value
      dest_1d[i] = 0xff000000 | result<<16 | result<<8 | result;
      
    }
    
   return dest_1d; 
   
  }
}


Input Image:


图像运算(九)——逻辑反(NOT)_第1张图片



Output Image :


图像运算(九)——逻辑反(NOT)_第2张图片


总结:有时候反面能看清楚某事物的本质。


你可能感兴趣的:(image,Integer,input,output)