Делая что-то, как сказал @ jeru-luke, результат будет таким:
import cv2 as cv
import numpy as np
img = cv.imread('z12.png', 1)
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
lower_green = np.array([30, 70, 20])
upper_green = np.array([70, 255, 255])
lower_blue = np.array([95, 110, 20])
upper_blue = np.array([135, 255, 255])
mask = cv.inRange(hsv, lower_green, upper_blue)
mask = cv.bitwise_not(mask)
bk = np.full(img.shape, 255, dtype=np.uint8) # white bk
fg_masked = cv.bitwise_and(img, img, mask=mask)
# get masked background, mask must be inverted
mask = cv.bitwise_not(mask)
bk_masked = cv.bitwise_and(bk, bk, mask=mask)
# combine masked foreground and masked background
final = cv.bitwise_or(fg_masked, bk_masked)
cv.imwrite('out_put.png', final)
cv.imshow('final', final), cv.waitKey(0)