Benchmark

This is a naive benchmarking code. It runs 11 out of the 14 watershed functions on the cameraman image:

1 f = adreadgray('cameraman.tif')
2 f = mmgradm(f, mmsebox())
3 adshow(f)

For each of the functions ran, the time is printed in seconds. At the end, the fastest function is highlighted.

 1 from watershed import *
 2 from ipdp.common import N4
 3 from time import time
 4 
 5 fns = [immersion, hierarchicalQueue, connectedComponents, unionFind, ift, chainCode, tieZone, orderInvariantToboggan, orderInvariantImmersion, shortestPaths, watershedCut]
 6 
 7 
 8 tmin = 1e400
 9 for fn in fns:
10     t0 = time()
11     w = fn(f, N4)
12     t1 = time()
13     print fn.__name__, ':', t1-t0, 's'
14     if t1 - t0 < tmin:
15         tmin = t1 - t0
16         fnmin = fn
17 
18 print
19 print 'And the winner is...'
20 print fnmin.__name__, ', with ', tmin, ' seconds!'
immersion : 4.22470998764 s
hierarchicalQueue : 3.18600702286 s
connectedComponents : 2.22009992599 s
unionFind : 7.41860103607 s
ift : 3.60099983215 s
chainCode : 7.45545196533 s
tieZone : 3.97756004333 s
orderInvariantToboggan : 6.35815000534 s
orderInvariantImmersion : 3.93057394028 s
shortestPaths : 3.40908885002 s
watershedCut : 2.37525105476 s

And the winner is...
connectedComponents , with  2.22009992599  seconds!