Skip to content

Commit

Permalink
add timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Irving committed Sep 23, 2016
1 parent 11377d3 commit b9f882e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion run_example.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
from __future__ import division, absolute_import, unicode_literals, print_function

import matplotlib.pyplot as plt

import maskslic as seg
from skimage.segmentation import mark_boundaries
from skimage.io import imread
import time

img = imread('chelsea.png')
roi = imread('chelsea_mask.png')

# roi = img_as_float(chelsea_mask())
roi = roi[:, :, 3] > 0

t1 = time.time()
# Note that compactness is defined differently because a grid is not used. Lower compactness for maskSLIC is equivalent
segments = seg.slic(img, compactness=10, seed_type='nplace', mask=roi, n_segments=12,
recompute_seeds=True, plot_examples=True)
print("Time: {:.2f} s".format(time.time() - t1))

plt.figure()
plt.title('maskSLIC')
plt.imshow(mark_boundaries(img, segments))
plt.contour(roi, contours=1, colors='red', linewidths=1)
plt.axis('off')


t1 = time.time()
segments = seg.slic(img, compactness=30, seed_type='grid', n_segments=80, plot_examples=False)
# segments[roi==0] = -1
print("Time: {:.2f} s".format(time.time() - t1))

plt.figure()
plt.title('Conventional SLIC')
Expand Down

0 comments on commit b9f882e

Please sign in to comment.