-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
47 lines (34 loc) · 1.18 KB
/
test.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
import cv2
import time
import numpy as np
from skimage import segmentation, color, filters
#img = data.coffee()
img = cv2.imread('data_scene_flow/training/image_2/000001_10.png', 0)
t1 = time.time()
labels1 = segmentation.slic(img, compactness=0.1, n_segments=500, sigma=0.8)
out1 = color.label2rgb(labels1, img, kind='avg')
# g = graph.rag_mean_color(img, labels1, mode='similarity')
# labels2 = graph.cut_normalized(labels1, g)
# out2 = color.label2rgb(labels2, img, kind='avg')
# labels2 = segmentation.felzenszwalb(img, scale=100, sigma=0.5, min_size=50)
# out2 = color.label2rgb(labels2, img, kind='avg')
# labels3 = segmentation.quickshift(img, kernel_size=3, max_dist=6, ratio=0.5)
# out3 = color.label2rgb(labels3, img, kind='avg')
labels4 = segmentation.watershed(filters.sobel(img), markers=250, compactness=0.001)
out4 = color.label2rgb(labels4, img, kind='avg')
print len(np.unique(out4))
out = np.vstack((img, out4))
cv2.imshow('r', out)
cv2.waitKey(0)
cv2.destroyAllWindows()
#
# fig, ax = plt.subplots(nrows=3, sharex=True, sharey=True, figsize=(6, 8))
#
# ax[0].imshow(img)
# ax[1].imshow(out1)
# ax[2].imshow(out2)
#
# for a in ax:
# a.axis('off')
#
# plt.tight_layout()