Background
The XOR binary operation takes two binary inputs and outputs 0 only when both the inputs are same ( i.e. if both the inputs are 0 and when both the inputs are 1 ) and else if both the inputs are not the same then it outputs 1. The XNOR binary operator is the complete inverse of the XOR binary operation. XNOR outputs 1 when both the inputs are same, else it produces 0. The functionality of XOR and XNOR are clarified by the help of the truth tables:
Understanding XOR & XNOR Mathematically:
The XORing of two images is carried out by performing XOR operation to the corresponding images of the two images to produce the output pixel value. For instance, suppose that we wish to XOR the integers 167 and 211 together using 8-bit integers. 167 is 10100111 in binary and 255 is 11010011. XORing these together in bitwise fashion, we have 01110100 in binary or 110 in decimal.
This is not at all the only implementation of this of the logical operators rather you can implement the logical XORing and XNORing using some thresholding to transform the digital image data into the binary format, or simply by taking the 0 pixel value as the logical 0 and the non-zero pixel values as the logical 1 value.
General Working
The XOR and XNOR operations are performed through a single pass module which during operation passes through the each pixel of each image and calculates the pixels of the output image by doing the respective operation on the corresponding pixels to calculate the output pixels. It is necessary to have two images of the identical size. In the sample program, if two images are not identical in size, then they are made of the same size ( explained below).
Guidelines for Use
We can illustrate the function of the XOR operator using
and
The images show a scene with two objects, one of which is common in both the images, and the other is not so. We can use XOR to compute the union of the images, i.e. highlighting all pixels which represent an object either in the first or in the second image, and not in both the images. First, we threshold the images, since the process is simplified by use binary input. If we XOR the resulting images
and
we obtain applying XOR operator on the image
and we obtain applying XNOR operator
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 speicality 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 grayscaled. Then it takes the BitmapData objects of the two input images.
It determines which image is bigger in width as well as in height. Then it scales the smaller image to acquire the size of the bigger image to make the sizes of both the images equal. Then the algorithm calculates the XORed image in the single pass through the image. The final output is an image showing the result of the effect of XOR operator on the two input images which is then displayed on the screen in the down most picture box.
Attachments:
Project Files: imageprocess_xor.zip