Reference: http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf Also used in: https://github.com/mapbox/pixelmatch (H/T @mourner)