"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

February 25, 2020

Day #328 - Simple masking function

Next task is segmentation. Basic Masking function.

#https://github.com/brine-io/u-net-segmentation-example/blob/master/U-Net%20Furniture%20Segmentation%20Example.ipynb
#https://github.com/brine-io/u-net-segmentation-example/blob/master/model/augmentations.py
import cv2
import numpy as np
def apply_mask(mask):
mask[mask < 100] = 0.0
mask[mask >= 100] = 255.0
def create_mask(img, mask):
img = img[:,:,:3]
mask = mask[:, :, :3]
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
apply_mask(mask)
cv2.imshow('input img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow('mask image',mask)
cv2.waitKey(0)
cv2.destroyAllWindows()
return img, mask
#load image
img = cv2.imread(r'E:\Learning_Days_2020\face1.jpg',1)
create_mask(img,img)
Happy Learning!!!

No comments: