Logical Operations on Images

img_rec = cv2.imread('rectangle.jpg', cv2.IMREAD_GRAYSCALE)
img_cir = cv2.imread('circle.jpg', cv2.IMREAD_GRAYSCALE)

plt.figure(figsize = [20,5])
plt.subplot(121);  plt.imshow(img_rec);
plt.subplot(122);  plt.imshow(img_cir);
print(img_rec.shape)

result = cv2.bitwise_and(img_rec, img_cir, mask = None)
plt.imshow(result);

result = cv2.bitwise_or(img_rec, img_cir, mask = None)
plt.imshow(result);

result = cv2.bitwise_xor(img_rec, img_cir, mask = None)
plt.imshow(result);

Arithmetic Operations Tutorial


References