We can perform bitwise NOT operation on an image using cv2.bitwise_not(). Here is the syntax to perform bitwise NOT operation on an image - cv2.bitwise_not(img) Steps To compute bitwise NOT on an image, you can follow the steps given below − Import...
We can perform bitwise NOT operation on an image using cv2.bitwise_not(). Here is the syntax to perform bitwise NOT operation on an image -
cv2.bitwise_not(img)
To compute bitwise NOT on an image, you can follow the steps given below −
Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you h**e already installed it.
Read the input image as a grayscale image using cv2.imread() method. Specify the full path of the image with the image type (i.e. png or jpg).
Compute the bitwise NOT on the input image using cv2.biwise_not(img).
Display the bitwise NOT image
Let's understand the bitwise NOT operation on an input image with the help of some Python examples.
In this example, we compute bitwise NOT of the input image.
We will use the following image as the Input File for this example −
When you run the above program, it will produce the following output.
Notice the color inversion of different shapes in the output window.
In this example, we compute bitwise NOT of the input image. Using this method, you can create a negative of an image.
We will use the following image as the Input File for this program −
When you run the above program, it will produce the following output −
Notice that the above output image is a negative image of the original input image.
In this example, we define an image circle of size 300×300. We perform bitwise NOT on this image.
When you run the above program, it will produce the following output −
The above output shows the 'Bitwise NOT' image is an inverted image of the image 'Circle'.