I have a screenshot taken from a chat platform and want to change the background of the chat to white, including profile pictures of participants. The code from this Question works fine if the name of the chat group is not displayed in the screenshot. Image 1 is an an example of the original image and image 2 is the so far achieved result:
And I want to achieve something similar to image 3:
This is the code I used from the question:
import cv2
import numpy as np
filename = ("/Users/user/Desktop/test2.png")
image = cv2.imread(filename)
hsv_img = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # rgb to hsv color space
s_ch = hsv_img[:, :, 1] # Get the saturation channel
thesh = cv2.threshold(s_ch, 5, 255, cv2.THRESH_BINARY)[1] # Apply threshold - pixels
above 5 are going to be 255, other are zeros.
thesh = cv2.morphologyEx(thesh, cv2.MORPH_OPEN,
cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7, 7))) # Apply opening morphological
operation for removing artifacts.
cv2.floodFill(thesh, None, seedPoint=(0, 0), newVal=128, loDiff=1, upDiff=1) # Fill
the background in thesh with the value 128 (pixel in the foreground stays 0.
image[thesh == 128] = (255, 255, 255) # Set all the pixels where thesh=128 to white.
cv2.imwrite('Filtering1.jpg', image) # Save the output image.
I am quite new with this so I need to know what should I add/ change in the code to achieve the result in image 3.
2