Region properties profiling results

This notebook contains timing results from the skimage.measure.regionprops function, to guide optimisation efforts.

First, we load up previously run timings. You can run these with the regprops.py script, though currently, saving these to csv requires a bit of wrangling.


In [1]:
import pandas as pd
data = pd.read_csv('profiles.csv', index_col=0)
data = data / 100 # results are from 100 runs
data.head()


Out[1]:
timing-cached timing-uncached
name
convex_image 1075.62 991.78
weighted_centroid 495.39 180.57
bbox 278.47 3.98
centroid 247.33 167.91
extent 198.12 184.80

Plotting

Now we plot the uncached timing against the cached timing, annotated with the function name thanks to mpld3 tooltips:


In [2]:
# set up environment
%matplotlib inline
from matplotlib import pyplot as plt
import mpld3
from mpld3 import plugins
mpld3.enable_notebook()

# make matplotlib plot
fig, ax = plt.subplots()
points = ax.scatter(data['timing-cached'], data['timing-uncached'],
                    s=100, alpha=0.5)
m = data.max().max()
ax.plot((0, m), (0, m), color='k', alpha=0.5)
ax.set_xlabel(u'timing-cached (µs / run)', size=15)
ax.set_ylabel(u'timing-uncached (µs / run)', size=15)
ax.set_xlim(-50, m + 50)
ax.set_ylim(-50, m + 50)

# set up mpld3 tooltip plugin
labels = ["{0}, ({1:.2f}, {2:.2f})".format(name, coords[0], coords[1])
          for name, coords in data.iterrows()]
tooltip = plugins.PointLabelTooltip(points, labels)

# connect the plugin to the mpl figure
plugins.connect(fig, tooltip)
plt.show()


Some interesting observations from this plot:

  • Properties needing a convex hull computation (convex_hull_image, solidity, convex_area) are much slower than other properties. Use them only if you are absolutely sure you need them.
  • Image moments are the next set of slow property calculations, and possibly the best candidate for optimisation.
  • Properties right of the diagonal suffer from a significant caching overhead, for some reason I don't yet understand. See particularly bbox.