![]() |
VOOZH | about |
Arithmetic operations such as addition, subtraction and bitwise operations (AND or, NOT, XOR) are fundamental techniques in image processing with OpenCV. These operations allow for the enhancement, analysis and transformation of image characteristics, making them essential for tasks like image clarification, thresholding, dilation and more.
Let's see the step by step implementation of Arithmetic operations,
opencv-python (cv2): Core library for image processing and computer vision.matplotlib.pyplot: For displaying images inside the notebook .numpy: Efficient array operations .The samples used can be downloaded from here.
Output:
1.1 Simple Addition
cv2.add(): Adds pixel values with saturation.
Output:
1.2 Weighted Addition
cv2.addWeighted(): Blends two images by specified weights and an optional scalar.
Parameters:
Output:
Output:
3.1 Bitwise AND
cv2.bitwise_and(): Only keeps pixels where both images have bits "on".
Output:
3.2 Bitwise OR
cv2.bitwise_or(): Keeps pixels if either image has a bit "on".
Output:
3.3 Bitwise XOR
cv2.bitwise_xor(): Keeps pixels if only one image (not both) has a bit "on".
Output:
3.4 Bitwise NOT
cv2.bitwise_xor(): Keeps pixels if only one image (not both) has a bit "on".
Output: