C# image processing Invert/Logical NOT by asif


The NOT binary operation takes one binary input and outputs 1 when the input is 0 and the output is 0 only if the input is 1. This functionality is shown by the help of the following table:

Using NOT boolean algebra allows you to represent things like:

    The sky is high and blue

Understanding NOT Mathematically:

   The NOT of two images is carried out by performing the inversion operation on the corresponding pixels of the two images to produce the output pixel value. For instance, suppose that we wish to NOT the integer 167 using 8-bit integers. 167 is 10100111 in binary. Inverting these together in bitwise fashion, we have 01011000 in binary or 88 in decimal.

General Working

   The NOT operations are performed through a single pass module which during operation passes through the each pixel of the image and calculates the pixels of the output image by doing the respective operation on the corresponding pixel to calculate the output pixels.

   Each pixel in the input image having a logical 1 (often referred to as foreground) has a logical 0 (associated with the background in the output image and vice versa. Hence, applying logical NOT to a binary image changes its polarity . The logical NOT can also be used for a graylevel image being stored in byte pixel format by applying it in a bitwise fashion. The resulting value for each pixel is the input value subtracted from 255:

O( i , j ) = 255 - I( i , j )

If this output image is normalized for an 8-bit display, we again obtain the photographic negative of the original input image.

Guidelines for Use

When the invert operator is applied on the image:

the following result is obtained:

The inversion technique can be used to get the negative of the image. This can be seen by applying the invert technique on the following image:

The following negative is obtained:

C# Sample Program:

   The algorithm is coded in C# using unsafe so the quality and speed of the program may not be affected. The class BitmapData is used to read and process the pixels in the image. This is the specialty of C# to provide such a speed even on image processing applications. There is a set of modules that are designed to implement the algorithm. The program expects that the input images are gray scaled. Then it takes the BitmapData objects of the two input images. It then subtracts the input pixel from 255( 11111111 ) to calculate the output pixel.


   Project Files: Inversion.zip