# Patent

## Title
Depth-based gain control

## Abstract

A method for depth mapping includes capturing an electronic image of a scene using an imaging device. The electronic image is processed to generate depth data with respect to the scene. The gain of the imaging device is set responsively to the depth data.

## Background
CROSS-REFERENCE TO RELATED APPLICATION
This application claims the benefit of U.S. Provisional Patent Application 61/267,050, filed Dec. 6, 2009, which is incorporated herein by reference.


FIELD OF THE INVENTION
The present invention relates generally to computer vision, and specifically to three-dimensional (3D) mapping and imaging.
BACKGROUND OF THE INVENTION
Various methods are known in the art for optical 3D mapping, i.e., generating a 3D profile of the surface of an object by processing an optical image of the object. This sort of 3D profile is also referred to as a depth map or depth image, and 3D mapping is also referred to as depth mapping.
Some methods of 3D mapping are based on projecting a laser speckle pattern onto the object, and then analyzing an image of the pattern on the object. For example, PCT International Publication WO 2007/043036, whose disclosure is incorporated herein by reference, describes a system and method for object reconstruction in which a coherent light source and a generator of a random speckle pattern project onto the object a coherent random speckle pattern. An imaging unit detects the light response of the illuminated region and generates image data. Shifts of the pattern in the image of the object relative to a reference image of the pattern are used in real-time reconstruction of a 3D map of the object. Further methods for 3D mapping using speckle patterns are described, for example, in PCT International Publication WO 2007/105205, whose disclosure is also incorporated herein by reference.
Other methods of optical 3D mapping project different sorts of patterns onto the object to be mapped. For example, PCT International Publication WO 2008/120217, whose disclosure is incorporated herein by reference, describes an illumination assembly for 3D mapping that includes a single transparency containing a fixed pattern of spots. A light source transilluminates the transparency with optical radiation so as to project the pattern onto an object. An image capture assembly captures an image of the pattern on the object, and the image is processed so as to reconstruct a 3D map of the object.
Still other methods of 3D mapping use a stereoscopic approach: Typically, two or more cameras at different positions capture respective images of the object. A computer analyzes the images to find the relative pixel offset of features of the object between the two images. The depths of the features are proportional to the respective offsets.
Automatic gain control (AGC) is used in many electronic imaging cameras. Various methods of AGC for such purposes are known in the art. For example, U.S. Pat. No. 5,712,682, whose disclosure is incorporated herein by reference, describes a system for generating a digital output signal representing a captured image. A sensor captures the image and generates a sensor output signal. A gain control amplifier is coupled to the sensor and receives the sensor output signal. The gain control amplifier has controls for applying various levels of gain to the sensor output signal. An analog-to-digital converter (ADC) is coupled to the gain control amplifier and generates the digital output signal representing the captured image. A processor, coupled to the ADC and the gain control amplifier, provides a control signal to the gain control amplifier for adjusting the level of gain applied by the amplifier.
As another example, U.S. Pat. No. 6,750,906, whose disclosure is incorporated herein by reference, describes an image processor system for a charge coupled device (CCD) or CMOS imaging system. The image processor system includes a histogram-based AGC circuit, which controls gain by adjusting the imaging system and adjusting a variable gain amplifier (VGA), as well as shutter timing for shutter gain.
SUMMARY
In image-based depth mapping systems, the quality of the depth information typically depends, inter alia, on the quality of the images that are captured and processed to generate the depth maps. Embodiments of the present invention that are described hereinbelow provide methods, apparatus and software that are useful in this regard.
There is therefore provided, in accordance with an embodiment of the present invention, a method for depth mapping, including capturing an electronic image of a scene using an imaging device. The electronic image is processed to generate depth data with respect to the scene, and a gain of the imaging device is set responsively to the depth data.
In a disclosed embodiment, capturing the electronic image includes projecting a pattern of optical radiation onto the scene, and processing the electronic image includes computing the depth data based on transverse shifts of the pattern in the image.
In some embodiments, processing the electronic image includes creating and outputting a depth map of the scene. Typically, setting the gain includes extracting a representative depth value from the depth map, and selecting the gain responsively to the representative depth value. Extracting the representative depth value may include computing a histogram of the depth data in the depth map, and selecting the representative depth value based on a set of high-frequency bins in the histogram.
In a disclosed embodiment, setting the gain includes selecting a pre-calibrated gain value based on the depth data. The method may include, prior to capturing the electronic image of the scene, computing gain calibration data by capturing and processing multiple images of a calibration object placed at different, respective distances from the imaging device, wherein the pre-calibrated gain value is selected based on the gain calibration data.
There is also provided, in accordance with an embodiment of the present invention, apparatus for depth mapping, including an imaging device, which is configured to capture an electronic image of a scene. A processor is configured to process the electronic image in order to generate depth data with respect to the scene, and to set a gain of the imaging device responsively to the depth data.
The present invention will be more fully understood from the following detailed description of the embodiments thereof, taken together with the drawings in which:



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 is a schematic, pictorial illustration of a system for three-dimensional (3D) mapping, in accordance with an embodiment of the present invention;
FIG. 2 is a schematic top view of an imaging device for use in 3D mapping, in accordance with an embodiment of the present invention;
FIG. 3 is a flow chart that schematically illustrates a method for gain calibration, in accordance with an embodiment of the present invention; and
FIG. 4 is a flow chart that schematically illustrates a method for gain control, in accordance with an embodiment of the present invention.



DETAILED DESCRIPTION OF EMBODIMENTS
The quality of the depth data that are generated by all sorts of image-based depth mapping systems depends on the quality of the electronic images captured by the system. The image quality can be particularly critical in systems that are based on projecting a pattern of light onto the scene of interest, such as the systems described in the PCT publications cited above. It is important in these systems that the imaging device produce an image of the scene in which the pattern appears with sufficient contrast between light and dark areas. If the gain of the imaging device is too high, bright areas will be washed out by saturation, whereas if the gain is too low, the pattern in dim areas may be masked by noise.
Due to the laws of physics, the brightness of the pattern that appears in the captured image drops strongly with increasing depth. Methods of AGC that are known in the art do not take this depth dependence into account and may therefore fail to achieve optimal contrast of the pattern in images of the patterned scene. Embodiments of the present invention, on the other hand, take the depth of objects in the scene into account explicitly: As explained in detail below, the electronic images captured by the imaging device are processed to generate depth data with respect to the scene, and the gain of the imaging device is then set responsively to the depth data.
System Description
FIG. 1 is a schematic, pictorial illustration of a system 20 for 3D mapping, in accordance with an embodiment of the present invention. In this example, an imaging device 22 is configured to capture images and generate 3D maps of a scene. The scene here includes a user 28 of the system (who is thus, in this case, the “object” of the imaging device, as well as its operator). The depth information in the 3D maps may be used by a host computer 24 as part of a 3D user interface, which enables the user to interact with games and other applications running on the computer and with elements shown on a display screen 26. (This sort of functionality is described, for example, in U.S. Patent Application Publication 2009/0183125, whose disclosure is incorporated herein by reference.) This particular application of system 20 is shown here only by way of example, however, and the mapping capabilities of system 20 may be used for other purposes, as well, and applied to substantially any suitable type of scenes and 3D objects.
In the example shown in FIG. 1, imaging device 22 projects a pattern of optical radiation onto the scene, and captures an image of the pattern that consequently appears on the body of user 28 and other objects in the scene (not shown in the figures). The optical radiation that is used for this purpose is typically, although not necessarily, in the infrared (IR) range, although visible or ultraviolet light may similarly be used. A processor in device 22, whose functionality is described in greater detail hereinbelow, processes the image of the pattern in order to generate a depth map of the body, i.e., an array of 3D coordinates, comprising a depth (Z) coordinate value of the body surface at each point (X,Y) within a predefined field of view. (In the context of an array of image-related data, these (X,Y) points are also referred to as pixels.) In the present embodiment, the processor computes the 3D coordinates of points on the surface of the user's body by triangulation, based on transverse shifts of the spots in the pattern, as described in the above-mentioned PCT publications WO 2007/043036, WO 2007/105205 and WO 2008/120217. This technique is referred to herein as “pattern-based depth mapping.”
FIG. 2 is a schematic top view of imaging device 22, in accordance with an embodiment of the present invention. Here the X-axis is taken to be the horizontal direction along the front of device 22, the Y-axis is the vertical direction (out of the page in this view), and the Z-axis extends away from device 22 in the general direction of the object being imaged by the assembly.
For 3D mapping, an illumination subassembly 30 illuminates the scene of interest with an appropriate pattern, such as a speckle pattern. For this purpose, subassembly 30 typically comprises a suitable radiation source 32, such as a diode laser, LED or other light source, along with optics, such as a diffuser 34 or a diffractive optical element, for creating the pattern, as described in the above-mentioned PCT publications. The pattern is projected onto the scene in a diverging beam 36.
An image capture subassembly 38 captures an image of the pattern on the surface of objects in the scene. Subassembly 36 typically comprises objective optics 42, which image the scene onto a detector 40, such as a CMOS image sensor, comprising a matrix of detector elements 41. The image sensor and objective optics define a field of view 44, which is typically contained within beam 36 in the region of interest of system 20.
As noted above, radiation source 32 typically emits IR radiation. Detector 40 may comprise a monochrome image sensor, without an IR-cutoff filter (not shown), in order to detect the image of the projected pattern with high sensitivity. To enhance the contrast of the image captured by detector 40, optics 42 or the detector itself may comprise a bandpass filter, which passes the wavelength of radiation source 32 while blocking ambient radiation in other bands.
A processor 46 receives and processes an electronic image input from subassembly 38. Processor 46 typically comprises an embedded microprocessor, which is programmed in software (or firmware) to carry out the processing functions that are described hereinbelow. The software may be provided to the processor in electronic form, over a network, for example; alternatively or additionally, the software may be stored on tangible computer-readable media, such as optical, magnetic, or electronic memory media. Processor 46 also comprises suitable input and output interfaces and may comprise dedicated and/or programmable hardware logic circuits for carrying out some or all of its functions. Details of some of these processing functions and circuits that may be used to carry them out are presented in U.S. Patent Application Publication 2010/0007717, whose disclosure is incorporated herein by reference.
Briefly put, processor 46 compares the image provided by subassembly 38 to a reference image of the pattern projected by subassembly 30 onto a reference plane at a known distance from device 22. (The reference image may be captured in advance as part of a calibration procedure and stored in a memory 48, for example.) The processor matches the local patterns in the captured image to those in the reference image and thus finds the transverse shift for each pixel, or group of pixels, within the plane. Based on these transverse shifts and on the known distance between the optical axes of subassemblies 30 and 38, the processor computes a depth (Z) coordinate for each pixel. Further details of a computational approach for converting transverse shifts of the pattern to depth values are presented in the above-mentioned provisional patent application.
Alternatively, other system configurations may be used for generating depth maps and are considered to be within the scope of the present invention. For example, the imaging device used in system may comprise two or more image sensors (not shown) and be configured on this basis to generate stereoscopic depth data, instead of or in addition to the pattern-based depth data. For this purpose, the processor may apply any method of stereoscopic processing that is known in the art. A method that uses both pattern-based and stereoscopic depth mapping techniques, which may be implemented by processor 46 in this context, is described in U.S. patent application Ser. No. 12/844,864, filed Jul. 28, 2010, which is assigned to the assignee of the present patent application and whose disclosure is incorporated herein by reference.
The intensity of the pattern in the images captured by subassembly 38 depends, among other parameters, on the distance of the object, ZOBJ, from device 22. (Since the distance between subassemblies 30 and 38 is typically much smaller than the distance to the object, we will assume that the distance from the object to the two subassemblies is equal, and refer to this distance as the distance from imaging device 22.) When an object is close to the imaging device, the intensity of the reflected light will be high and may saturate detector 40. When the object is distant, the reflected light intensity will be low, and the contrast between bright and dark parts of the pattern may therefore be close to the noise level.
In order to avoid saturation, as well as to enhance the visibility of the pattern in the captured images when the object is far away, processor 46 uses the distance (depth) from device 22 to object 28, ZOBJ, in determining the gain that will be used in image capture subassembly 38. The overall gain may be determined by a single setting or by a combination of settings, which may include, for example, the electronic shutter speed and gain of on-board amplifiers in detector 40, as well as the gain of analog front-end and digital processing circuits (not shown) between detector 40 and processor 46. The term “gain,” as used in the context of the present patent application and in the claims, should therefore be understood broadly to include any and all settings that affect the relation between the radiation intensity that is incident on detector elements 41 and the magnitude of the corresponding electronic output signals (analog or digital). Methods for calibrating and applying depth-based gain are described hereinbelow. These methods may be used by themselves or in conjunction with AGC methods and circuits that are known in the art.
Methods for Depth-Based Gain Control
FIG. 3 is a flow chart that schematically illustrates a method for gain calibration, in accordance with an embodiment of the present invention. This method is used to compute the parameters of a gain adjustment function, which are then stored in a look-up table (LUT) in memory 48. For convenience and clarity of description, this method and the method of FIG. 4 are described with reference to specific elements of system 20, as illustrated and described above. The principles of these methods, however, may be implemented in substantially any sort of image-based depth mapping system. All such implementations are considered to be within the scope of the present invention.
The method of FIG. 3 uses a calibration object, such as a flat, diffusely reflecting screen. In one embodiment, the object is a Lambertian reflector with reflectivity close to 100%. To begin the calibration procedure, the calibration object is placed at a known distance from imaging device 22, at an object placement step 50. Illumination subassembly 30 in device 22 is operated to project the appropriate pattern onto the calibration object, and image capture subassembly 38 meanwhile captures electronic images of the calibration object, at an image capture step 52. During this step, the gain of subassembly 38 is optimized to bring the pixel values in the output image into a desired range. For example, the gain may be adjusted so that the gray-scale value of the brightest pixels in the output image is 80% of the maximum possible value (i.e., 80% of the saturation limit). Alternatively, other criteria may be used in setting the gain.
The gain value found at step 52 is typically stored in memory 48, in a LUT containing gain settings as a function of object distance, at a table storage step 54. Alternatively, the gain value that is stored for each distance may be reduced by a certain factor, relative to the value that was found at step 52, in order to prevent the image from saturating when there is strong ambient light in the scene. Typically, the reduction factor is between 1.5 and 4. For example, if the factor is chosen to be 2, then the gain for each distance will be the value that would have brought the gray level during calibration to 80%/2=40% of the saturation level.
The steps above are repeated for multiple different distances of the calibration object, until the full range of interest is covered, at a completion step 56. For thorough and precise coverage, the object distance may be stepped over the entire depth measurement range of device 22, from minimum to maximum depth. The size of the steps may be as small as 0.1% of the maximum depth for precise calibration, or they may be larger depending on application requirements and the capacity of memory 48.
The calibration method of FIG. 3 is typically carried out at the time of manufacture of imaging device 22, but such calibration may, alternatively or additionally, be performed in the field. In a production run of imaging devices, the calibration method may be applied to each device individually, or it may be performed on only one or a few of the devices in order to compute calibration parameters to be stored by all of the devices.
FIG. 4 is a flow chart that schematically illustrates a method for gain control, in accordance with an embodiment of the present invention. This method uses the gain LUT (or other gain parameters) that were computed and stored in memory 48 using the method of FIG. 3. Illumination subassembly 30 in imaging device 22 projects patterned illumination onto the scene of interest, and image capture subassembly 38 captures an image of the pattern on the scene, at an image capture step 60. Processor 46 processes the captured image to create a depth map of the scene, at a depth map computation step 62.
Processor 46 checks whether the image captured by detector 40 at step 60 was saturated, at a saturation checking step 63. For example, the processor may compute a histogram of the gray levels of the image, or over a certain region of interest in the image. If the number of pixels at saturation levels is above a predetermined threshold (for example, more than 1% of the pixels are saturated), the processor will reduce the gain by a certain factor, such as 20%, at a gain adjustment step 70.
If the image is not saturated, processor 46 uses the depth data in the depth map to adjust the gain of device 22. Typically, this computation is based on a statistical analysis, such as a histogram of the depth values, which the processor computes at a statistical computation step 64. This histogram of depth values may be calculated over the entire depth map or only over a part of the volume that is mapped by the sensor. For example, a 3D region of interest may be defined, over which the depth histogram is then computed. Based on the statistical analysis, the processor chooses a representative depth value for the scene, at a value extraction step 66. In one embodiment, the processor identifies the bins in the histogram having the highest frequencies, and choose the representative depth value based on the depth values of these bins. For example, the processor may set the representative depth value equal to the average depth value of the bins in the highest percentile of frequency. Alternatively, other suitable statistical measures may be used in computing the representative depth value.
For the representative depth value calculated at step 66, processor 46 looks up the nearest depth value in the LUT in memory 48, at a lookup step 68. The processor reads out the corresponding calibrated gain value and then sets the gain of imaging device 22 to this calibrated value, at gain adjustment step 70. Alternatively, when the representative depth value falls in between two of the depth values in the table, the processor may read out two or more of the calibrated gain values and interpolate to find the optimal gain setting. Further alternatively, the calibration data stored in memory 48 may comprise parameters of an analytical function of the depth, and the processor computes the value of this analytical function in order to adjust the gain.
The gain value computed and set at step 70, whether due to saturation detected at step 63 or to the representative depth value found at step 66, will be applied to the next image captured by device 22 at step 60. (When the method of FIG. 4 is implemented in hardware logic, steps 64-68 may be carried out over all depth maps, and the result of step 68 may simply be overridden when the image is found to have been saturated.) Because object depth in the scene tends to change slowly, the gain setting that is made in this way is likely to be nearly optimal for subsequent images.
Referring back to the choice of optimal gain setting made at step 52, the choice of a gain that causes a perfect Lambertian reflector to reach about 80% of the saturation level is useful in that it ensures that images of diffusely-reflecting objects in the scene, with reflectance up to 100%, will not be saturated. It is possible that a strong specular reflector in the scene will still result in an area of saturation. In practice, however, objects of this sort are not usually encountered, and extracting their depth values from an image that is captured using means like device 22 is difficult or impossible in any case.
When the image captured by device 22 is either saturated or very dark, the method of FIG. 4 may not give good results, since processor 46 may be unable to compute meaningful depth values over much or even all of the scene. Therefore, as a preliminary step, the processor may apply a conventional AGC algorithm, such as those described in the patents cited in the Background section, in order to make an initial gain setting before beginning to find depth-based gain values.
Although the embodiments described above are directed to adjustment of the gain of image capture subassembly 38, similar calibration and adjustment procedures may be used, alternatively or additionally, to control the intensity of the radiation output by illumination assembly 30 in imaging device 22 as a function of the distance of an object from the imaging device. Furthermore, the techniques described above may be applied, mutatis mutandis, in controlling the gain of an imaging device on the basis of other sorts of depth data, such as ranging measurements made using a time-of-flight detector or using any other suitable technique that is known in the art.
It will thus be appreciated that the embodiments described above are cited by way of example, and that the present invention is not limited to what has been particularly shown and described hereinabove. Rather, the scope of the present invention includes both combinations and subcombinations of the various features described hereinabove, as well as variations and modifications thereof which would occur to persons skilled in the art upon reading the foregoing description and which are not disclosed in the prior art.

## Claims

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.

2. The method according to claim 1, wherein capturing the electronic image comprises projecting a pattern of optical radiation onto the scene, and wherein processing the electronic signal comprises computing the depth data based on transverse shifts of the pattern in the image.

3. The method according to claim 1, wherein processing the electronic signal comprises creating and outputting a depth map of the scene.

4. The method according to claim 3, wherein setting the gain comprises extracting a representative depth value from the depth map, and selecting the gain responsively to the representative depth value.

5. The method according to claim 4, wherein extracting the representative depth value comprises computing a histogram of the depth data in the depth map, and selecting the representative depth value based on a set of high-frequency bins in the histogram.

6. The method according to claim 1, and comprising, prior to capturing the electronic image of the scene, computing gain calibration data by capturing and processing multiple images of a calibration object placed at different, respective distances from the imaging device, wherein the pre-calibrated gain value is selected based on the gain calibration data.

7. Apparatus for depth mapping, comprising:
an imaging device, which comprises a matrix of detector elements configured to capture an image of a scene 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; and
a processor, which is configured to process the electronic signal output by the imaging device in response to a first image in order to generate depth data with respect to the scene, and to set 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.

8. The apparatus according to claim 7, wherein the imaging device is configured to project a pattern of optical radiation onto the scene, and wherein the processor is configured to compute the depth data based on transverse shifts of the pattern in the image.

9. The apparatus according to claim 7, wherein the processor is configured to create and output a depth map of the scene, comprising the depth data, based on the electronic image.

10. The apparatus according to claim 9, wherein the processor is configured to extract a representative depth value from the depth map, and to select the gain responsively to the representative depth value.

11. The apparatus according to claim 10, wherein the processor is configured to compute a histogram of the depth data in the depth map, and to select the representative depth value based on a set of high-frequency bins in the histogram.

12. The apparatus according to claim 7, wherein prior to capturing the electronic image of the scene, gain calibration data are computed by capturing and processing multiple images of a calibration object placed at different, respective distances from the imaging device, wherein the processor is configured to select the pre-calibrated gain value based on the gain calibration data.