Brian Holt's histogram of gradient code: ready for merging