I have a grayscale image and want to remove the white rectangle from the image and join the upper and lower images.
The input image is
The output image should look like
Code that I have done so far
image = cv2.imread('./rotated_image.png')
mask = np.zeros(image.shape[:2], np.uint8)
backgroundModel = np.zeros((1, 65), np.float64)
foregroundModel = np.zeros((1, 65), np.float64)
rectangle = (78, 10, 971, 30)
cv2.grabCut(image, mask, rectangle, backgroundModel, foregroundModel,5, cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask == 2)|(mask == 0), 0, 1).astype('uint8')
image = image * mask2[:, :, np.newaxis]
plt.imshow(image)
plt.show()
cv2.imwrite("op.png", image)
so the output is:
After that, I tried subtracting from the main image
image1 = cv2.imread('./rotated_image.png')
image2 = cv2.imread('./op.png')
subtracted = cv2.subtract(image1, image2)
plt.imshow(subtracted)
plt.show()
cv2.imwrite("sub.png", subtracted)
So, the white rectangle becomes black but I want to remove it and merge the image.