Automatic Image Enhancement by Content Dependent Exposure Correction

We describe an automatic image enhancement technique based on features extraction methods. The approach takes into account images in Bayer data format, captured using a CCD/CMOS sensor and/or 24-bit color images; after identifying the visually significant features, the algorithm adjusts the exposure level using a “ camera response ”-like function; then a ﬁnal HUE reconstruction is achieved. This method is suitable for handset devices acquisition systems (e.g., mobile phones, PDA, etc.). The process is also suitable to solve some of the typical drawbacks due to several factors such as poor optics, absence of ﬂashgun, and so forth.


INTRODUCTION
Reduction of processing time and quality enhancement of acquired images is becoming much more significant. The use of sensors with greater resolution combined with advanced solutions [1,2,3,4] aims to improve the quality of resulting images. One of the main problems affecting image quality, leading to unpleasant pictures, comes from improper exposure to light. Beside the sophisticated features incorporated in today's cameras (i.e., automatic gain control algorithms), failures are not unlikely to occur. Some techniques are completely automatic, cases in point being represented by those based on "average/automatic exposure metering" or the more complex "matrix/intelligent exposure metering." Others, again, accord the photographer a certain control over the selection of the exposure, thus allowing space for personal taste or enabling him to satisfy particular needs.
Inspite of the great variety of methods [5,6], for regulating the exposure and the complexity of some of them, it is not rare for images to be acquired with a nonoptimal or incorrect exposure. This is particularly true for handset devices (e.g., mobile phones) where several factors contribute to acquire bad-exposed pictures: poor optics, absence of flashgun, not to talk about "difficult" input scene lighting conditions, and so forth.
There is no exact definition of what a correct exposure should be. It is possible to abstract a generalization and to define the best exposure that enables one to reproduce the most important regions (according to contextual or perceptive criteria) with a level of gray or brightness, more or less in the middle of the possible range.
Using postprocessing techniques an effective enhancement should be obtained. Typical histogram specification, histogram equalization, and gamma correction to improve global contrast appearance [7] only stretch the global distribution of the intensity. More adaptive criterions are needed to overcome such drawback. In [8,9] two adaptive histogram equalization techniques, able to modify intensity's distribution inside small regions are presented. In particular the method described in [9], splits the input image into two or more equal area subimages based on its gray-level probability density function. After having equalized each subimage, the enhanced image is built taking into account some local property, preserving the original image's average luminance. In [10] point processing and spatial filtering are combined together while in [11] a fuzzy logic approach to contrast enhancement is presented. Recent approaches work in the compressed domain [12] or use advanced techniques such as curvelet transform [13], although both methods are not suited for real-time processing.
The new exposure correction technique described in this paper is designed essentially for mobile sensors applications. This new element, present in newest mobile devices, is particularly harmed by "backlight" when the user utilizes a mobile device for video phoning. The detection of skin characteristics in captured images allows selection and proper enhancement and/or tracking of regions of interest (e.g., faces). If no skin is present in the scene the algorithm switches automatically to other features (such as contrast and focus) tracking for visually relevant regions. This implementation differs from the algorithm described in [14] because the whole processing can also be performed directly on Bayer pattern images [15], and simpler statistical measures were used to identify information carrying regions; furthermore the skin feature has been added.
The paper is organized as follows. Section 2 describes the different features extraction approaches and the exposure correction technique used for automatic enhancement. The "arithmetic" complexity [16] of the whole process is estimated in Section 3. In Section 4 experimental results show the effectiveness of the proposed techniques. Also some comparisons with other techniques [7,9] are reported. Section 5 closes the paper tracking directions for future works.

APPROACH DESCRIPTION
The proposed automatic exposure correction algorithm is defined as follows.
(1) Luminance extraction. If the algorithm is applied on Bayer data, in place of the three full color planes, a subsampled (quarter size) approximated input data (see Figure 1) is used.
(2) Using a suitable features extraction technique the algorithm fixes a value to each region. This operation permits to seek visually relevant regions (for contrast and focus the regions are block-based, for skin recognition the regions are associated to each pixel). (3) Once the "visually important" pixels are identified (e.g., the pixels belonging to skin features) a global tone correction technique is applied using as main parameter the mean gray levels of the relevant regions.

Features extraction: contrast and focus
To be able to identify regions of the image that contain more information, the luminance plane is subdivided in N blocks of equal dimensions (in our experiments we employed N = 64 for VGA images). For each block, statistical measures of "contrast" and "focus" are computed. Therefore it is assumed that well-focused or high-contrast blocks are more relevant compared to the others. Contrast refers to the range of tones present in the image. A high contrast leads to a higher number of perceptual significance regions inside a block. Focus characterizes the sharpness or edgeness of the block and is useful in identifying regions where highfrequency components (i.e., details) are present.
If the aforementioned measures were simply computed on highly underexposed images, then the regions having better exposure would always have higher contrast and edgeness compared to those that are obscured. In order to perform a visual analysis revealing the most important features regardless of lighting conditions, a new "visibility image" is constructed by pushing the mean gray level of the input green Bayer pattern plane (or the Y channel for color images) to 128. The push operation is performed using the same function that is used to adjust the exposure level and it will be described later.
The contrast measure is computed by simply building a histogram for each block and then calculating its deviation (2) from the mean value (3). A high deviation value denotes good contrast and vice versa. In order to remove irrelevant peaks, the histogram is slightly smoothed by replacing each entry with its mean in a ray 2 neighborhood. Thus, the original histogram entry is replaced with the gray levelĨ[i]: Histogram deviation D is computed as where M is the mean value: The focus measure is computed by convolving each block with a simple 3 × 3 Laplacian filter.
In order to discard irrelevant high-frequency pixels (mostly noise), the outputs of the convolution at each pixel are thresholded. The mean focus value of each block is computed as where N is the number of pixels and the thresh(·) operator discards values lower than a fixed threshold Noise. Once the values F and D are computed for all blocks, relevant regions will be classified using a linear combination of both values.
Features extraction pipeline is illustrated in Figure 2.

Features extraction: skin recognition
As before a visibility image obtained by forcing the mean gray level of the luminance channel to be about 128 is built. Most existing methods for skin color detection usually threshold some sort of measure of the likelihood of skin colors for each pixel and treat them independently. Human skin colors form a special category of colors, distinctive from the colors of most other natural objects. It has been found that human skin colors are clustered in various color spaces [17,18]. The skin color variations between people are mostly due to intensity differences. These variations can therefore be reduced by using chrominance components only.
Yang et al. [19] have demonstrated that the distribution of human skin colors can be represented by a twodimensional Gaussian function on the chrominance plane. The center of this distribution is determined by the mean vector µ and its shape is determined by the covariance matrix Σ; both values can be estimated from an appropriate training data set. The conditional probability p( x|s) of a block belonging to the skin color class, given its chrominance vector x is then represented by where d( x) is the so-called Mahalanobis distance from the vector x to the mean vector µ and is defined as The value d( x) determines the probability that a given block belongs to the skin color class. The larger the distance d( x), the lower the probability that the block belongs to the skin color class s. Such class has been experimentally derived using a large data set of images acquired at different conditions and resolution using CMOS-VGA sensor on "STV6500-E01" evaluation kit equipped with "502 VGA sensor" [20]. Due to the large quantity of color spaces, distance measures, and two-dimensional distributions, many skin recognition algorithms can be used. The skin color algorithm is independent of exposure correction, thus we introduce two different alternative techniques aimed to recognize skin regions (as shown in Figure 3).
(1) By using the input YCbCr image and the conditional probability (5), each pixel is classified as belonging to a skin region or not. Then a new image with normalized gray-scale values is derived, where skin areas are  properly highlighted (Figure 3c). The higher the gray value the higher the probability to compute a reliable identification.
(2) By processing an input RGB image, a 2D chrominance distribution histogram (r, g) is computed, where r = R/(R+G+B) and g = G/(R+G+B). Chrominance values representing skin are clustered in a specific area of the (r, g) plane, called "skin locus" (Figure 4c), as defined in [21]. Pixels having a chrominance value belonging to the skin locus will be selected to correct exposure.
For Bayer data, the skin recognition algorithm works on the RGB image created by subsampling the original picture, as described in Figure 1.

Exposure correction
Once the visually relevant regions are identified, the exposure correction is carried out using the mean gray value of those regions as reference point. A simulated camera response curve is used for this purpose, which gives an estimate of how light values falling on the sensor become final pixel values (see Figure 5). Thus it is a function: where q represents the "light" quantity and I the final pixel value [1]. This function can be expressed [14,22] by using a simple parametric closed form representation: where parameters A and C can be used to control the shape of the curve and q is supposed to be expressed in 2-based logarithmic unit (usually referred as "stops"). These parameters could be estimated, depending on the specific image acquisition device, using the techniques described in [22] or chosen experimentally. The offset from the ideal exposure is computed using the f curve and the average gray level of visually relevant regions avg as where Trg is the desired target gray level. Trg should be around 128 but its value could be slightly changed especially when dealing with Bayer pattern data where some postprocessing is often applied. The luminance value Y (x, y) of a pixel (x, y) is modified as follows: Note that all pixels are corrected. Basically the previous step is implemented as a lookup table (LUT) transform ( Figure 6 shows two correction curves with different A, C parameters). Final color reconstruction is done using the same approach described in [23] to prevent relevant HUE shifts and/or color desaturation: where R, G, and B are the input color values. Note that when Bayer pattern is used (10) is directly applied on RGB pixels.   Figure 7: Automatic exposure correction pipeline: given a color image as input (for Bayer data image the pipeline is equivalent), the visibility image is extracted using a forced gray-level mean of about 128, then the skin percentage measure is achieved to seek if the input image contains skin features. In the case of skin feature existence (the value is more than the threshold T), the mean of selected skin pixel is achieved. If skin is not present the contrast and focus measures are computed and the mean of relevant blocks is performed. Finally, by fixing the correction curve, the exposure adjustment of luminance channel is accomplished.

COMPLEXITY ANALYSIS
The computational resources required by the algorithm described are negligible and indeed the whole process is well suited for real-time applications. Instead of the asymptotic complexity, the arithmetic complexity has been described to estimate the algorithm real-time execution [16]. More precisely, the sum of operations per pixel has been computed.
The following weights will be used: (1) w a for basic arithmetic operations: additions, subtractions, comparisons, and so forth; (2) w m for semicomplex arithmetic operations: multiplications, and so forth; (3) w l for basic bits and logical operations: bits-shifts, logical operations, and so forth; (4) w c for complex arithmetic operations: divisions, exponentials, and so forth.
First the main functions of the algorithm will be analyzed; then the overall C complexity will be estimated. A simple analysis of the computational cost can be carried out exploiting the main processing blocks composing the working flow of Figure 7 and considering the worst-case scenario, when the algorithm is applied directly on the RGB image. The following assumptions are considered:

Visibility image construction
The visibility image is obtained by computing the mean of the extracted Y and the offset from desired exposure by applying (9). Once the offset is known the visibility image is built using equations (10) to (13). Therefore

Skin identification
Since the skin probabilities are computed on Cr, Cb channels defined in the 0-255 range (after the 128-offset addition) the probabilities for each possible Cr, Cb pair can be precomputed and stored in a 256 × 256 LUT. The dimensions of this LUT, due to its particular shape (Figure 8), can be reduced up to 136 × 86 discarding the pairs having zero value: (1) lookup of skin probabilities (simple access to LUT): 1w a ; (2) thresholding of skin probabilities: 1w a ; (3) computation of skin mean gray value: 1w a +(1/ tot)w c . Therefore

Measures computation
The mean, focus, and contrast of each block are computed.
(1) Mean values of each block: (num ×w c )/ tot (since accumulated gray levels inside each block can be obtained from the visibility image and only the divisions have to be done). (2) Focus computation: (3) Contrast computation: 256 11w a + w m + w c + 1w c num tot . Therefore:

Relevant blocks identification
Once focus and contrast are obtained, blocks are selected using their linear combination value: (1) linear combination of focus and contrast: (num / tot)(1w a + 2w m ); (2) comparison between the linear combination and a selection value: (num / tot)w m . Therefore Image correction This step can be considered computationally equivalent to the visibility image construction since the only difference is the mean value used for corrective LUT loading, therefore: The algorithm complexity is then obtained by adding all the above values: The overall complexity is hence well suited for real-time applications (note that the ratio num / tot will always be very small, since tot num). For example given a 640×480 VGA input image (tot = 307 200), a fixed num = 64 blocks, and the worst k = 70, the complexity becomes Therefore C i = w l + 21.587w a + 12.054w m + 6.054w c . (24) That is cost-effective and suitable for real-time processing applications.

EXPERIMENTAL RESULTS
The proposed technique has been tested using a large database of images acquired at different resolutions, with different acquisition devices, both in Bayer and RGB format. In Figure 7 the exposure correction pipeline is illustrated. The whole process is organized as follows: the "visibility" image is extracted from the input image, and then the skin percentage measure is achieved to determine if the input image contains skin features; once the type of features is known the extraction of the mean values is performed, and finally the correction is accomplished. In the Bayer case the algorithm was inserted in a real-time framework, using a CMOS-VGA sensor on STV6500-E01 evaluation kit equipped with 502 VGA sensor [20]. In Figure 9 screen shots of the working environ- For sake of comparisons we have chosen both global and adaptive techniques, able to work in real-time processing: standard global histogram equalization and gamma correction [7] and adaptive luminance preservation equalization technique [9]. The parameters of gamma correction have been manually fixed to the mean value computed by the proposed algorithm. Experiments and comparisons with existing methods are shown in Figures 13, 14, and 15.
In Figure 13a the selected image has been captured by using an Olympus C120 camera. It is evident that an overexposure is required. Both equalization algorithms in Figures 13b  and 13c have introduced excessive contrast correction (the faces and the high frequencies of the two persons have been destroyed). The input image of Figure 14a has been captured by using an Olympus E10 camera. In this case the adaptive equalization algorithm in Figure 14b has performed a better enhancement than in the previous example (Figure 13b), but the image still contains an excessive contrast correction (the face has lost skin luminance). The equalization in Figure 14c  has completely failed the objective due to the large amount of background lightness. The exclusion of the skin features extraction phase is evident looking at the enhancement difference between Figures 14e and 14f. Finally, Figure 15 shows a poorly exposed image in Figure 15a Figure 13: Experimental results with relative luminance histograms: (a) input image, (b) adaptive equalized image using the technique described in [9], (c) equalized image, (d) gamma correction output with fixed average value defined by the proposed method, and (e) proposed algorithm output. The selected image (a) has been captured by using an Olympus C120 camera. Almost all gamma-corrected images in Figures 13d, 14d, and 15d contain excessive color desaturation.
Results show how often histogram equalization, that do not take into account images features, leads to excessive contrast enhancement while simple gamma correction leads to excessive color desaturation. Therefore the features analysis capability of the proposed algorithm permits contrast en-hancement taking into account some strong peculiarity of the input image.

CONCLUSIONS
A method for automatic exposure correction, improved by different feature extraction techniques, has been described.
The approach is able to analyze the Bayer data captured by a CCD/CMOS sensor, or the corresponding color generated picture; once the skin key features have been identified, the algorithm adjusts the exposure level using a "camera response"-like function. The method can solve some of the typical drawbacks featured by handset devices due to poor optics, absence of flashgun, difficult scene lighting conditions, and so forth. The overall computation time needed to apply the proposed algorithm, is negligible, thus it is well suited for real-time applications. Experiments show the effectiveness of the techniques in both cases. Future works will investigate the use of curvelet transform for enhanced exposure correction [13].