'How to desaturate the background of an image in Python
I need to desaturate the background of this kind of images.
I thought I can find the largest contour and desaturate everything around.
So far I can find the largest contour(not perfect). How I can desaturate the background around it ?
UPDATE (2022)
I'm editing my question since I didn't got an answer that helped me. Maybe now it will be more clear.
So below you can see the original image and the mask. As you can see in the original image the background around the person has a tint of blue/magenta in it. Using the mask i have, I would like to desaturate that blue/magenta tint. How I can do that ? I know I need to inverse that mask...but from there...I'm lost...
import cv2
image = cv2.imread('picture.jpg')
imgray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
imgray = cv2.GaussianBlur(imgray, (9, 9), 0)
ret, thresh = cv2.threshold(imgray, 0, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(image, contours, -5, (0, 255, 0), 3)
cv2.imwrite('output.jpg', image)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|