1. A method for depth mapping, comprising: capturing an image of a scene using an imaging device, which comprises a matrix of detector elements and which is configured to output an electronic signal representing the captured image, wherein the imaging device has a gain that determines a relation between an intensity of radiation incident on the detector elements and a magnitude of the electronic signal; processing the electronic signal output by the imaging device in response to a first image to generate depth data with respect to the scene; and setting the gain of the imaging device that is to be applied to one or more second images, captured subsequently to the first image by selecting a pre-calibrated gain value based on the depth data.