-
Notifications
You must be signed in to change notification settings - Fork 0
/
segmentation.py
47 lines (43 loc) · 1.18 KB
/
segmentation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 24 14:00:53 2018
@author: ibrahim
"""
from grabcut2 import *
from edge_segmentation import *
import scipy.ndimage as nd
from skimage.filters import gaussian
from skimage.segmentation import morphological_chan_vese
def get_segmentation(img_path,blur=7):
gray = cv2.imread(img_path,0)
# gray=rgb2gray(img)
faceCascade = cv2.CascadeClassifier('image.xml')
rect = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)
face_mask = np.zeros_like(gray)
#print(rect != 0)
if (rect is not ()):
# todo face
face_mask = grabcut(img_path,rect)
# egdesegmentation
edge_mask = edge_seg(img_path)
new_mask = face_mask + edge_mask
new_mask[new_mask > 1] = 1
#new_mask = edge_mask
# maximum = new_mask.max()
# print(maximum)
# new_mask = new_mask / maximum
mask = gaussian((new_mask*255).astype('uint8'), blur)
img = gray
mask = mask[:,:]
# mask = new_mask
return mask
img = img*mask
plt.imshow(img),plt.colorbar(),plt.show()
#img_path = 'images/house 2-small.jpg'
#segmentation(img_path)