Foundations of semi-differential invariance with applications to recognition under affine distortion