The ray projection and its application to recovering a projective geometric transformation and an affine lighting change between two objects are mathematically studied. A novel technique, viz., variable contour, is proposed for accurately evaluating the ray projection. Moreover, a novel flexible framework of the ray projection is devised for the joint recovery of the eight parameters for the projective transformation and the two parameters for the lighting change. Finally, the framework is experimentally evaluated by recovering a variety of geometric and photometric transformations between real images of indoor and outdoor scenes. Its robustness to image blur and occlusion is demonstrated. Its versatility is illustrated through matching different objects in different classes.