Arithmetic Operations on Images
Arithmetic Operations like Addition, Subtraction, and Bitwise Operations(AND, OR, NOT, XOR) can be applied to the input images.
Function | Uses |
---|---|
add(image1, image2) | This function is used to add two images. |
subtract(image1, image2) | This function is used to subtract two images. |
addWeighted(image1, weight1, image2, weight2, gammaValue) | This is also known as Alpha Blending. This is nothing but a weighted blending process of two images. |
bitwise_and(image1, image2, destination, mask) | This performs bitwise and logical operations between two images. |
bitwise_or(image1, image2, destination, mask) | This performs bitwise or logical operations between two images. |
bitwise_not(image, destination, mask) | This performs bitwise not logical operations between an image and a mask. |
bitwise_xor(image1, image2, destination, mask) | This performs bitwise xor logical operations between two images. |
Image Addition
We can add two images by using the cv2.add() method. This directly adds up image pixels in the two images.
cv2.add(image1, image2)
Image Alpha Blending
Alpha blending is the process of overlaying a foreground image on a background image which can be done using the addWeighted() method.
cv2.addWeighted(image1, weight1, image2, weight2, gammaValue)
Image Subtraction
We can subtract the pixel values in two images and merge them with the help of cv2.subtract(). The images should be of equal size and depth.
cv2.subtract(image1, image2)
Bitwise And
Bit-wise conjunction of input array elements.
cv2.bitwise_and(image1, image2, destination, mask)
Bitwise Or
Bit-wise disjunction of input array elements.
cv2.bitwise_or(image1, image2, destination, mask)
Bitwise Not
Inversion of input array elements.
cv2.bitwise_not(image, destination, mask)
Bitwise Xor
Bit-wise exclusive-OR operation on input array elements.
cv2.bitwise_xor(image1, image2, destination, mask)
Python OpenCV Cheat Sheet
The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It’s designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you’re an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we’ve gathered all the vital OpenCV concepts and explained them in simple terms. We’ve also provided practical examples to make things even clearer. You’ll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It’s all here to help you on your journey of discovering the amazing world of computer vision.
Table of Content
- Python OpenCV Cheat Sheet 2023
- Core Operations
- Drawing Shapes and Text on Images
- Arithmetic Operations on Images
- Morphological Operations on Images
- Geometric Transformations on Image
- Image Thresholding
- Edge/Line Detection (Features)
- Image Pyramids
- Changing the Colorspace of Images
- Smoothing Images
- Working With Videos
- Camera Calibration and 3D Reconstruction
Contact Us