Logical OR/NOR

Common Names: OR, NOR

Brief Description

OR and NOR are examples of logical operators having the truth-tables shown in Figure 1.

Figure 1 Truth-tables for OR and NOR.

As can be seen, the output values of NOR are simply the inverses of the corresponding output values of OR.

The OR (and similarly the NOR) operator typically takes two binary or graylevel images as input, and outputs a third image whose pixel values are just those of the first image, ORed with the corresponding pixels from the second. A variation of this operator takes just a single input image and ORs each pixel with a specified constant value in order to produce the output.

How It Works

The operation is performed straightforwardly in a single pass. It is important that all the input pixel values being operated on have the same number of bits in them or unexpected things may happen. Where the pixel values in the input images are not simple 1-bit numbers, the OR operation is normally (but not always) carried out individually on each corresponding bit in the pixel values, in bitwise fashion.

Guidelines for Use

We can illustrate the function of the OR operator using

and

The images show a scene with two objects, one of which was moved between the exposures. We can use OR 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. First, we threshold the images, since the process is simplified by use binary input. If we OR the resulting images

and

we obtain

This image shows only the position of the object which was at the same location in both input images. The reason is that the objects are represented with logically 0 and the background is logically 1. Hence, we actually OR the background which is equivalent to NANDing the objects. To get the desired result, we first have to invert the input images before ORing them. Then, we obtain

Now, the output shows the position of the stationary object as well as that of the moved object.

As with other logical operators, OR and NOR are often used as sub-components of more complex image processing tasks. OR is often used to merge two images together. Suppose we want to overlay

with its histogram, shown in

First, an image editor is used to enlarge the histogram image until it is the same size as the grayscale image as shown in

Then, simply ORing the two gives

The performance in this example is quite good, because the images contain very distinct graylevels. If we proceed in the same way with

we obtain

Now, it is difficult to see the characters of the histogram (which have high pixel values) at places where the original image has high values, as well. Compare the result with that described under XOR.

Note that there is no problem of overflowing pixel values with the OR operator, as there is with the addition operator.

ORing is usually safest when at least one of the images is binary, i.e. the pixel values are 0000... and 1111... only. The problem with ORing other combinations of integers is that the output result can fluctuate wildly with a small change in input values. For instance 127 ORed with 128 gives 255, whereas 127 ORed with 126 gives 127.

Interactive Experimentation

You can interactively experiment with this operator by clicking here.

Exercises

1. NOR

and

and AND their negatives. Compare the results.

2. Why can't you use thresholding to produce a binary image containing both objects of

and

? Use graylevel ORing to combine the two images. Can you detect all the locations of the objects in the two images? What changes if you invert the images before combining them.

3. In the example above, how could you make the histogram appear in black instead of white? Try it.

4. Summarize the conditions under which you would use OR to combine two images rather than, say, addition or blending.

References

R. Gonzalez and R. Woods Digital Image Processing, Addison-Wesley Publishing Company, 1992, pp 47 - 51, 171 - 172.

E. Davies Machine Vision: Theory, Algorithms and Practicalities, Academic Press, 1990, Chap. 2.

B. Horn Robot Vision, MIT Press, 1986, pp 47 - 48.

Local Information

Specific information about this operator may be found here.

More general advice about the local HIPR installation is available in the Local Information introductory section.