added calculations of distance from pixels