Peter Kovesi's functions for image processing