import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('../../pic/b.jpg')
mask = np.ones(img.shape[:2],np.uint8)*2
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
rect = (1,1,img.shape[0],img.shape[1])



newmask = cv2.imread('mask.jpg',0)

mask[newmask == 0] = 0
mask[newmask == 255] = 1

mask, bgdModel, fgdModel = cv2.grabCut(img,mask,None,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_MASK)
mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]



newmask = cv2.imread('mask1.jpg',0)

mask[mask == 2] = 0
mask[mask != 0] =2
mask[newmask == 0] = 0
mask[newmask == 255] = 1


plt.imshow(mask),plt.colorbar(),plt.show()


mask, bgdModel, fgdModel = cv2.grabCut(img,mask,None,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_MASK)
plt.imshow(mask),plt.colorbar(),plt.show()
mask = np.where((mask==2)|(mask==0),0,1).astype('uint8')

img = img*mask[:,:,np.newaxis]
plt.imshow(img),plt.colorbar(),plt.show()



#cv2.grabCut(img,mask,rect,bgdModel,fgdModel,15,cv2.GC_INIT_WITH_RECT)
#mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
#plt.imshow(mask2)
#plt.show()
#img = img*mask2[:,:,np.newaxis]
#plt.imshow(img),plt.colorbar(),plt.show()
