Machine vision algorithm