Part 5 -Bitwise AND operation to mask useless area in image

Kumar Brar
4 min readFeb 19, 2020

--

In continuation to our lane line detection program, our next step is to mask out the entire region which is not useful. When you look at our basic Canny image as shown below, you will realize that the only area in which, we are interested is the one highlighted in the below image.

Region of Interest

We simply want to mask out all the other unrelated information which will otherwise interfere with the effective processing of our road image.

It is very important to understand that the more concise the data size, the more effective will be the processing and functioning of our program. Unnecessarily, processing the data which is of no use, will effect the program in unusual ways and can also increase the response time. In real world scenario, it is very important that our program eliminates the data which is of no use at the earliest. Then, the camera (or eye) of our self-driving car will then focus only on the area on which it must concentrate and take its decision on detecting the lane lines and adhering to them , so as to avoid any accident or unusual activity.

To get our desired area, we need to do Bitwise AND operation of the adjacent pixels of the two images to get only the region in which we are interested. For this, we need a basic understanding of the AND operation. As you know, our image is a collection of 0s and 1s and here we do AND operation on the below shown two images to obtain the region of interest.

figure 2 : Just applying AND operation on both the images to obtain Region of Interest

I hope everyone is clear with the binary numbers and also aware of the AND and OR operation with binary numbers. Binary numbers are nothing but a collection of 0s and 1s. For eg: To binary equivalent of number 23 is as shown in the image below :

Binary representation of number 23

Now, why we are doing the AND operation to obtain the region of interest between the two images is that the AND operation will return the same result. Let me make it more clear with the help of example. As shown in the below image, we want to perform the AND operation on all pixel values between the two images, so as to obtain the region of interest.

White region has value of (11111111–1 byte) and black region has value (00000000)

Now, when we perform AND operation between 0 and 1, the result is always 0. But the AND operation of 1 and 1 gives us 1. So, we just want to highlight the region in which we are interested by making use of the Bitwise AND operation. Some people aware of the binary numbers and about AND and OR , may have understood that using OR operation will not help here.

A simple example is the one shown below. Please note, that when both the pixel values are 1, the result is also one and otherwise it is 0. And as shown below, the AND operation is giving the output as one of the same bit number and not any other value.

The highlighted yellow boxes show that the two numbers are identical.

Note: Computing the Bitwise AND of both the images, takes the Bitwise AND of each homologous pixel in both arrays, ultimately masking the Canny image to only show the region of interest traced by the polygonal contour of the mask.

So, when we make the desired changes in our program, we get the focus area or the region of interest as shown :

Region of Interest

Bibliography

--

--

Kumar Brar
Kumar Brar

Written by Kumar Brar

I am a lifelong learner with an ongoing curiosity to learn new things and share them with others. This helps in brainstorming and implementing new ideas.

No responses yet