-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_example.py
33 lines (23 loc) · 854 Bytes
/
run_example.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
import matplotlib.pyplot as plt
import maskslic as seg
from skimage.segmentation import mark_boundaries
from skimage.io import imread
img = imread('chelsea.png')
roi = imread('chelsea_mask.png')
# roi = img_as_float(chelsea_mask())
roi = roi[:, :, 3] > 0
segments = seg.slic(img, compactness=30, seed_type='nplace', mask=roi, n_segments=12,
recompute_seeds=True, plot_examples=True)
plt.figure()
plt.title('maskSLIC')
plt.imshow(mark_boundaries(img, segments))
plt.contour(roi, contours=1, colors='red', linewidths=1)
plt.axis('off')
segments = seg.slic(img, compactness=30, seed_type='grid', n_segments=80, plot_examples=False)
# segments[roi==0] = -1
plt.figure()
plt.title('Conventional SLIC')
plt.imshow(mark_boundaries(img, segments))
plt.contour(roi, contours=1, colors='red', linewidths=1)
plt.axis('off')
plt.show()