Trying to recolor the hair using a mask. Firstly segmented hair from the main image & trying to make it a realistic one changing HSV value but according to my code the result is not the accurate output that i am looking for. Any solution?
img = cv2.imread('model-demo.jpg')
img = cv2.resize(img, (256, 256))
_, mask_hair = cv2.threshold(mask_hair, thresh=210, maxval=255, type=cv2.THRESH_BINARY)
#cutting specific portion of hair from image
cut_mask = np.invert(mask_hair)
res = np.where(cut_mask, 0, img)
#HSV value changing for new color
hsv = cv2.cvtColor(res, cv2.COLOR_BGR2HSV)
hsv[:,:,0] +=120
hsv[:,:,1] +=60
hsv[:,:,2] -=20
hsv = cv2.cvtColor(res, cv2.COLOR_HSV2RGB)
plt.imshow(hsv)
The image I have:
The result according to my code:
The result I want:
PART- 2
Also tried to multiply the image mask with color but end the end it doesn't even matter...
img = cv2.resize(cv2.imread('model-demo.jpg'),(256,256))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
mask = cv2.resize(cv2.imread('./mask.jpg'),(256,256))
mask_clr = np.zeros([256,256,3],dtype=np.uint8)
mask_clr[np.where((mask_hair==255).all(axis = 2))] = [0, 255, 0]
imgMultiply = cv2.multiply(img,mask_clr)
mask_clr --> green mask:









+=or-=. I believe that you're getting an overflow of integer values (e.g. adding 120 causes to go over 255).