An implementation of http://www.ams.sunysb.edu/~jsbm/papers/pami99.pdf