import cv2 import numpy as np from PIL import Image import matplotlib.pyplot as plt img_1 = cv2.imread('source/data_03.jpg') cv2.imshow("img1", img_1) img_2 = np.zeros(img_1.shape, dtype=np.uint8) img_2[200:400, 200:400] = 255 cv2.imshow("img2", img_2) result_or = cv2.bitwise_or(img_1, img_2) result_and = cv2.bitwise_and(img_1, img_2) result_not = cv2.bitwise_not(img_1, img_2) result_xor = cv2.bitwise_xor(img_1, img_2) cv2.imshow("or", result_or) cv2.imshow("and", result_and) cv2.imshow("not", result_not) cv2.imshow("xor", result_xor) cv2.waitKey() cv2.destroyWindow()