A scanner includes a camera, a light source for generating a probe light incorporating a spatial pattern, an optical system for transmitting the probe light towards the object and for transmitting at least a part of the light returned from the object to the camera, a focus element within the optical system for varying a position of a focus plane of the spatial pattern on the object, unit for obtaining at least one image from said array of sensor elements, unit for evaluating a correlation measure at each focus plane position between at least one image pixel and a weight function, a processor for determining the in-focus position(s) of each of a plurality of image pixels for a range of focus plane positions, or each of a plurality of groups of image pixels for a range of focus plane positions, and transforming in-focus data into 3D real world coordinates.