1. A method, comprising: providing a device that projects a pattern; capturing a reference image of the pattern using an image sensor by projecting the pattern onto a reference surface while at least a first part of the reference surface, containing a first portion of the pattern, is located at a first distance from the image sensor and while at least a second part of the reference surface, containing a second portion of the pattern, is located at a second distance, different from the first distance, from the image sensor, and combining the first and second portions of the pattern into the reference image; registering the captured reference image in a frame of reference of the device; storing the registered reference image in a memory associated with the device; and generating a three-dimensional (3D) map of an object, different from the reference surface, after storing the registered reference image by projecting the pattern onto the object, capturing a test image of the pattern on the object, and measuring local transverse shifts of the pattern in the test image relative to the reference image that is stored in the memory.