Modelling the Scene Dependent Imaging in Cameras with a Deep Neural Network
Seonghyeon Nam Seon Joo Kim
cs.CV







Modelling the Scene Dependent Imaging in Cameras 
 
with a Deep Neural Network
    Seonghyeon Nam

Yonsei University

shnnam@yonsei.ac.kr





Seon Joo Kim

Yonsei University

seonjookim@yonsei.ac.kr

    December 30, 2023
=========================================================================================================================






We present a novel deep learning framework that models the scene dependent image processing inside cameras.
Often called as the radiometric calibration, the process of recovering RAW images from processed images (JPEG format in the sRGB color space) is essential for many computer vision tasks that rely on physically accurate radiance values.
All previous works rely on the deterministic imaging model where the color transformation stays the same regardless of the scene and thus they can only be applied for images taken under the manual mode.
In this paper, we propose a data-driven approach to learn the scene dependent and locally varying image processing inside cameras under the automode.
Our method incorporates both the global and the local scene context into pixel-wise features via multi-scale pyramid of learnable histogram layers.
The results show that we can model the imaging pipeline of different cameras that operate under the automode accurately in both directions (from RAW to sRGB, from sRGB to RAW) and we show how we can apply our method to improve the performance of image deblurring. 





§ INTRODUCTION

Deep learning has significantly changed the approaches for solving computer vision problems.
Instead of analytic solutions with some combinations of hand chosen features, probabilistic/physical models and some optimizations, most methods now turn to deep learning which is a deeper neural network that relies on big data.
Deep learning has shown superb performance in many computer vision problems including image recognition <cit.>, face recognition <cit.>, segmentation <cit.>, etc. 
Image processing problems such as super-resolution <cit.> and colorization <cit.> are also solved with deep learning now, which provides effective ways to process input images and output images that fit the given task. 

In this paper, we introduce a new application of using deep learning for image processing: modelling the scene dependent image processing. 
We are especially interested in modelling the in-camera imaging pipeline to recover RAW images from camera processed images (usually in the form of JPEG in the sRGB color space) and vice versa.
Usually called as the radiometric calibration, this process is important for many computer vision tasks that require accurate measurement of the scene radiance such as photometric stereo <cit.>, intrinsic imaging <cit.>, high dynamic range imaging <cit.>, and hyperspectral imaging <cit.>. 

There are two strategies with regards to the image processing in cameras, namely, the photographic reproduction model and the 
photofinishing model <cit.>. 
In the photographic reproduction model, the image rendering pipeline is fixed meaning that a raw RGB value will always be mapped to an RGB value in the processed image regardless of the scene. 
Taking photos under the manual mode triggers this model and all previous radiometric calibration methods work only in this mode. 





In the photofinishing model, the image processing inside the camera varies (possibly in a spatially varying manner) in order to deliver visually optimal picture depending on the shooting environment <cit.>.
This scene dependent mode will be activated usually when the camera is operated under the auto-mode.
Figure <ref> compares the photos of a scene captured under the manual mode and under the auto-mode. 
In (b), the scene became brighter and the colors were enhanced compared to (a).
It shows that the color rendering will be dependent on the scene in the auto-mode.
Scene dependency in cameras were also verified in <cit.>.
As mentioned above, none of the previous work can deal with the scene dependent color rendering.
This is a problem as there are many photometry related topics in computer vision that have access to only automatically taken images (e.g. internet images) as in <cit.>. 
Moreover, smartphone cameras have become the major source for images and the many phone cameras only work in the auto-mode.  

The goal of this paper is to present a new algorithm that can model the camera imaging process under the "auto" mode.  
To deal with the scene dependency, we take the data-driven approach and design a deep neural network.
We show that modelling the image processing using conventional CNN-based approaches is not effective for the given task, 
and propose a multi-scale pyramid of learnable histogram <cit.> to incorporate both the global and the local color histogram into pixel-wise features.
The extracted multi-scale contextual features are processed with our CNN to model the scene dependent and locally varying color transformation.

To the best of our knowledge, this is the first paper that can extract RAW images from processed images taken under the auto setting.
Being able to radiometrically calibrate smartphone cameras is especially a significant contribution of this work. 
We show that we can model both the forward rendering (RAW to sRGB) and the reverse rendering (sRGB to RAW) accurately using our deep learning framework. 

We further apply our work to image deblurring. 
A blurred image is first transformed to the RAW space, in which a deblurring algorithm is executed.
The deblurred image is then transformed back to the sRGB space through our deep network. 
We show that performing deblurring in this fashion give much better results over deblurring in the nonlinear sRGB space.








§ RELATED WORK

In-camera Image Processing (Radiometric Calibration) 


In the early works of radiometric calibration, the relationship between the scene radiance and the image value was explained  just by a tonemapping function called the camera response function. 
Different models of the response function <cit.> as well as robust estimation algorithms <cit.> were introduced.
More comprehensive reviews of the radiometric calibration literature is presented in <cit.>.

In <cit.>, a more complete in-camera imaging pipeline that includes processes such as the white balance, the color space transformation, and the gamut mapping in addition to the tone-mapping was introduced. 
With the new parametric model for the imaging, the work also presented an algorithm for recovering the parameters from a set of images using a scattered point interpolation scheme. 
Using a similar pipeline, a probabilistic model that takes into account the uncertainty in the color rendering was recently proposed in <cit.>.

As mentioned earlier, all previous works are based on the assumption that the color rendering inside the camera is deterministic and therefore cannot be applied for photos taken under the automode or by phone cameras.
In comparison, our deep network framework learns the scene dependent image processing through given data and thus can be used for automatically captured photos.



Deep Learning for Low-level Vision 


Deep learning has been very successful in image classification tasks, and the deep neural networks are now being applied to various problems in computer vision including the low-level vision tasks.
In the field of low-level vision, convolutional neural networks (CNNs) are used to exploit the local context information for various applications such as image super-resolution <cit.>, denoising <cit.>, and filtering <cit.>. While the input and the output of these applications are RGB images, the learned mapping is more of a structural mapping rather than being a color mapping.

Recently, deep learning based image colorization has been studied <cit.>, of which the objective is to restore chrominance information from a single channel luminance image. These works exploit the high-level semantic information to determine the chrominance of pixels by using CNNs, similar to those used in the high-level recognition tasks <cit.>. 
In this paper, we show that color histogram based low-level features extracted using our deep network are more efficient for the given task compared to the high-level CNN features extracted from above previous work. 


In <cit.>, an automatic photo adjustment method using a multi-layer perceptron was proposed. 
They feed the concatenation of global color features and semantic maps to a neural network system to find the scene dependent and the locally varying color mapping. 
As with the other data-driven image enhancement techniques <cit.>, the features for the color mapping in their work are manually selected. 
However, one of the key properties behind the success of deep learning is in its ability to extract good features for the given task automatically. 
Instead of using manual features, we propose an end-to-end trainable deep neural network to model the scene dependent in-camera image processing.




§ DATASET

An essential ingredient for any deep learning system is a good dataset.
To model the image processing inside the camera from data, we need pairs of RAW images and its corresponding images in the nonlinear sRGB color space with JPEG format. 
Using the RAW-JPEG shooting mode, which is now supported by most cameras including Android based smartphones, we can collect many pairs of corresponding RAW and sRGB images.
In this paper, we collected images using three digital cameras: Canon 5D Mark III, Nikon D600, and Samsung Galaxy S7.
All pictures were taken under the auto-mode and the features like Auto Lighting Optimizer in the Canon camera that triggers locally varying processing such as contrast enhancement were all turned on. 
Some of the images in our dataset are shown in fig:Dataset. 
As can be seen, our dataset contains various kind of scenes including outdoor, indoor, landscape, portrait, and colorful pictures.
The number of images in the dataset are 645, 710, and 290 for the Canon, the Nikon, and the Samsung camera, respectively.
50 images of varying scenes for each camera were selected for the test sets.
In training phase, we extract multiple patches from images on the fly by using the patch-wise training method, which is described in sec:patch_training.
Therefore, we can make millions of training examples from hundreds of image data.

One thing to take notice is the white balancing in the imaging pipeline.
The white balance is one of the main factors in determing the image color.
While the white balance factor can be learned in the forward pipeline (from RAW to JPEG) as shown in <cit.>, estimating the white balance in the reverse pipeline is seemingly a more difficult task as the illumination is already normalized in the JPEG image.
After the images are illumination normalized with the white balancing, it becomes an one-to-many mapping problem as any illuminant could have been mapped to the current image.

Fortunately, the meta information embedded in images (EXIF data) provides the white balancing information.
It provides three coefficients, which are the scale factors for the red, the green, and the blue channels. 
All the RAW images in our dataset are first white balanced using this information from the EXIF data. 
Therefore, the mapping that we learn in our system is from the white balanced RAW to sRGB, and vice versa. 







§ DEEP LEARNING FRAMEWORK FOR MODELLING THE IMAGING PIPELINE

In this work, our goal is to model the imaging pipeline by computing the function f that maps RAW images to sRGB images and the function f^-1 that maps sRGB images to RAW images. 
The training data consist of RAW-sRGB pairs 𝒟={X^i, Y^i}_i=0^n, where X is the RAW image, Y represents the sRGB image, and n is the number of training examples.
Since the deep neural networks are not invertible, we train f and f^-1 separately.
Without the loss of generality, the algorithm that follows will be explained for the forward mapping f.
Exactly the same process can be applied for learning the reverse mapping f^-1.

The mapping function f under the auto-mode varies according to the scene and the local neighborhood.
The function is formally described as: 

    Y^i_x = f(X^i_x, Φ^i, Ω^i_x),

where i is the image index, x is the pixel index, Φ represents the global scene descriptor, and Ω indicates local descriptor around a pixel. 
We propose a deep neural network that learns the scene dependent color mapping f including both Φ and Ω in eq:model in an end-to-end manner.

To optimize the parameters of the proposed network, we need to define the loss function that computes the difference between the estimation and the ground truth. 
We minimize l_2 error from the training data as follows:

    L = 1/n∑_i=0^n‖ f(X^i)-Y^i ‖^2.


As explained, the color mapping f is dependent on the global and the local context.
Coming up with features that can describe this scene dependency manually is a difficult task. 
One way to compute the features for this problem is to use pre-trained CNNs like the VGG network <cit.> and finetune using our training set.
As we show in Section 5, applying conventional CNN based structures do not capture good features for the scene dependency in our task. 
From the camera's point of view, it would be difficult to run a high-level scene recognition module for the scene dependent rendering due to the computational load. 
Therefore, it is reasonable to conjecture that the scene dependent color mapping relies mostly on low-level features such as 
the contrast and the color distributions, which are computationally cheaper than the semantic features. In this work, we exploit color histogram as the feature to describe the scene.



 §.§ Learnable Histogram

Color histogram is one of the most widely used features to describe images. In deep networks that use histograms, the centers and the widths of the bins are hand-tweaked by the user. In addition, since the computation of histograms is not differentiable, histograms are precomputed before training deep networks. Meanwhile, Wang  <cit.> recently proposed the learnable histogram method, in which the key is a specialized differentiable function that trains the optimized histogram from data with deep networks in an end-to-end manner.

With the learnable histogram, the bin for the value of an element in the feature map is determined by the following voting function:

    ψ_k,b(x_k) = max{ 0, 1-| x_k - μ_k,b|× w_k,b}.

k and b are the index of the feature map element and the output bin, respectively.
x_k is the value of the k-th element in the feature map, μ_k,b and w_k,b are the center and the width of the b-th bin.  
The histogram is built by accumulating the bins computed with the function ψ_k,b(x_k) as illustrated in fig:learnable_histogram. 
The centers μ_k,b and the widths w_k,b are trainable parameters and are optimized together with other parameters of the deep network.

In this work, we adopt the histogram voting function eq:learnable_histogram of the learnable histogram to extract image features for our task of modelling the imaging pipeline.
By introducing a multi-scale pyramid of histograms, we design the pixel-wise color descriptor for the global and the local context.
In <cit.>, the learnable histogram was applied to the intermediate semantic feature maps to exploit global connect global Bag-of-Words descriptors, which in turn improves the performance of semantic segmentation and object detection.
As we are looking for more low level color features instead of high-level semantic features, we directly connect the learnable histogram to the input image to extract RGB color histograms as show in fig:overview (a).
Moreover, by putting multi-scale pooling layers on the output of the learnable histogram, our new network can extract the global and the local descriptors for each pixel.




To effectively extract the color distribution, it is necessary to decouple the brightness and the chromaticity distribution. 
Therefore, we first convert the RGB values to a lightness (L) and chromaticity (rg) channels before the image goes through the learnable histogram as follows:

    L    = (R + G + B) / 3,
    
    r    = R / (R+G+B),
    
    g    = G / (R+G+B).




 §.§ Multi-Scale Pyramid Pooling Layer

The output dimension of eq:learnable_histogram is H × W × (C × B), where H, W and C are the number of the height, width and channel of the input, C is the number of bins of the histogram. To get the global and the local color histogram, multiple average poolings with different pooling size are applied to the output feature maps as shown in fig:overview (b). We concatenate the multi-scale features corresponding to the same input pixel to incorporate the global and local context into pixel-wise features. Formally, our multi-scale pyramid of histogram features is described as:

    Ω^i_x = [h_x^1, h_x^2, ..., h_x^s],

where h_x^s is the feature vector of s-th scale of the histogram layer corresponds to the pixel x.

In our implementation, we compute four scales of the multi-scale pyramid by cascading three 3×3 average pooling layers followed by a global average pooling for the global histogram.
The strides of the 3 local histogram layers are 1, 2, and 2, respectively.



 §.§ Patch-Wise Training Method and Implementation Details


As illustrated in fig:overview, our deep network is trained with image patches instead of using the whole image. 
In the training phase, the whole image is first forwarded to the learnable histogram module (fig:overview (a)).
Then a number of patches are randomly selected from both the input image and the histogram feature maps (fig:overview (b)).
Specifically, patches are first extracted from the input image, and the feature maps that correspond to each patch are cropped to form the multi-scale features.
Finally, only those selected patches are used for training the CNN weights as shown in fig:overview (c).


This patchwise training has the advantage of being able to generate many training examples from a small dataset as well as being efficient in both time and memory. 
At the test time, the whole image and feature maps are forwarded to generate the full size output.



For the configuration of our network, we used 6 bins for the learnable histogram, the initial bin centers were set to (0, 0.2, 0.4, 0.6, 0.8, 1.0), and the initial bin widths were set to 0.2 as described in <cit.>.
After the global and the local features are extracted using the learnable histogram, the descriptors are concatenated with the input RGB image. 
Then, we apply 1×1 convolution filters to mix all input pixels and feature information, followed by two 3×3 additional convolutions to estimate the output.



§ EXPERIMENTS




 §.§ Experimentation setup

The training images are preprocessed as follows. 
The RAW images are first demosaiced, normalized to have the max value of 1, and white-balanced using the EXIF metadata.
Images are downsized and cropped to 512×512 images.
In all camera datasets, we use 80% of images for the training and the remaining 20% for the validation, excluding the 50 test images.
For the training, we use the Adam optimizer <cit.> to minimize our cost function. 
The batch size is 4, and sixteen 32×32 sparse patches are randomly extracted from it, which makes 64 training examples per batch.
According to <cit.>, our training with a small fraction of images does not affect the convergence.

With a GTX 1080 GPU, we can train the proposed network of 100 epochs within an hour.

As explained before, we cannot compare the proposed method with existing radiometric calibration methods as they are deterministic models for specific manual settings and cannot be applied to automode cameras.
Instead, we compare the proposed method with the following four baseline methods.

	
  ∙ Multi-layer Perceptron: 
		We designed a MLP that consists of two hidden layers with 64 nodes each.
		The MLP learns an RGB to RGB color mapping without considering the scene dependency.
		We implemented the MLP by applying 1 × 1 convolution to images.
	
  ∙ SRCNN <cit.>: 
		We used the SRCNN that consists of five 3 × 3 convolutional layers without pooling, and this is a simple attempt to model the scene dependency.
	
  ∙ FCN <cit.> and HCN <cit.>: 
		Since we only have hundreds of images in the training data, we adopt a pixel-wise sampling method <cit.> to a hypercolumn network (HCN) to generate sufficient training signals. It cannot be applied to FCN since sample position is usually a fractional number in downsampled feature maps.
		Note that we only use VGG network layers from ( to ) for the FCN and (, , ) for the HCN, since our machine cannot handle large feature maps computed from high-definition input images (e.g. 1920×2880). For the FCN, we use the FCN-8S configuration on the reduced VGG network. We finetune both the FCN and the HCN using the pretrained VGG network.























 §.§ Experimental results

Table <ref> shows the quantitative results using the 50 test images in our dataset for each camera.
In the table, PSNR values comparing the RGB values of the recovered image with the ground truth are reported. 
For both the forward rendering (RAW-to-sRGB) and the reverse rendering (sRGB-to-RAW), the proposed method outperforms the other baseline methods in all categories except for very few Min and MaX errors among test images. 

Results using the MLP were usually worse than the other methods and this indirectly indicates the scene dependency in photographs. 
While the SRCNN showed some ability to deal with the scene dependency, its receptive field is limited to local neighborhoods and it cannot model the global scene context.
The MLP and the SRCNN are optmized to model the mean of the color mapping in dataset and some of high values of the Min and the Max values in the results can be explained that some test images exist around the mean of our dataset.

One can expect that hierarchical CNN features are able to capture the local and the global scene context that are useful for the scene dependent imaging. 
However, the experimental results show that they are not as efficient as our color histogram features.
We attribute the bad performance of the FCN to the fact that the FCN is not sufficiently trained on only hundreds of training examples.
Although we could sufficiently train the HCN through the in-network sampling method <cit.>, concatenating multi-level upsampled feature maps consume large memory for high-definition images from consumer cameras, which cannot be handled in test time.
In summary, the results clearly show that our deep network that learns the local and the global color distribution is more efficient for accurately modelling the scene dependent image processing in cameras.

fig:qualitative shows some of the examples of the image recovery. 
The figure shows that the proposed method can model the in-camera imaging process accurately in a qualitative way.
It also shows that the other baseline methods also do a reasonable job of recovering images as the scene dependency applies to a set of specific colors or regions.








 §.§ Analysis

We conducted more experiments to analyze the scene dependent processing learned by our network. 
For the analysis, we use two RAW images A and B. 
We first extract the learnable histogram feature from A, and replace the extracted histogram of B with that of A before injecting it to the DNN forward process. 
Note that the RAW image itself is the same, we just simulate the scene context change by changing the histogram. 
The intention of this analysis is to see how our network responds to the changes in the scene context. 

fig:discussion_1 shows the result of manipulating the global luminance histogram. 
The histogram in fig:discussion_1 (a) indicates the luminance distribution of a high contrast image, which is typical for backlit photos. We replace the histogram (a) with that of image (b) during the forward process of (b).
fig:discussion_1 (c) and (d) show the result of the manipulation. As can be seen, the deep network brightens shadow regions and darken highlight regions.
The network recognizes many dark regions and bright regions in the given histogram, and compensates by shifting the brightness to the middle (red in fig:discussion_1 (d)) compared to the original histogram (blue in fig:discussion_1 (d)). Note that it is what the Auto Lighting Optimizer of Canon cameras does as described in <cit.>.

In fig:discussion_2, we show the result of manipulating the global chrominance histogram by going through the same process as explained above. 
By changing the global color context of image B with that of A, we can observe that our network responses more strongly to green and brown colors than the original.
We can interpret this as our network recognizing the context of A as a natural scene from color distribution, trying to make natural objects like trees more visually pleasing. 

These examples show that our deep network recognizes specific scene context such as high contrast or nature images, and manipulates the brightness and colors to make images more visually pleasing as done in the scene dependent imaging pipeline of cameras. 
The experiments  also show that the deep network does not memorize each example and can infer the mapping under various scene contexts.




 §.§ Application to Image Deblurring

To show the effectiveness of the proposed method, we apply it to the image deblurring application.
It is well known that the blur process actually happens in the RAW space, but most deblurring algorithms are applied to the sRGB images since the RAW images are usually unavailable.
Tai  <cit.> brought up this issue and showed that being able to linearize the images have a significant effect in the deblurred results. 
However, the radiometric calibration process in <cit.> is rather limited and can only work under manual camera settings. 

We show that we can improve the deblurring performance on images taken from a smartphone camera (Samsung Galaxy S7) in automode. 
To do this, we use the image deblurring method of Pan  <cit.>, which is a blind image deblurring method that uses the dark channel prior. We use the source code from the authors’ website and the default settings except for the kernel size.
The RAW images are first computed from the corresponding sRGB images using the sRGB-to-RAW rendering of the proposed method, deblurred, and converted back to sRGB images using the RAW-to-sRGB rendering of the proposed method.

fig:deblurring shows the deblurring results. 
As expected, the deblurring method <cit.> does not work well on nonlinear sRGB images and 
there are some artifacts on deblurred scenes.
On the other hand, the deblurring algorithm works well using our framework.
The recovered images are much sharper and there are no significant artifacts.



§ CONCLUSION

In this paper, we presented a novel deep neural network architecture that can model the scene dependent image processing inside cameras. 
Compared to previous works that employ imaging models that are scene independent and can only work for images taken under the manual mode, 
our framework can be applied to the images that are taken under the auto-mode including photos from smartphone cameras.
We also showed the potential of applying the proposed method for various computer vision tasks via image deblurring examples.



§ ACKNOWLEDGEMENT

This work was supported by Global Ph.D. Fellowship Program through the National Research Foundation of Korea (NRF) funded by the Ministry of Education (NRF-2015H1A2A1033924), and the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIP) (NRF-2016R1A2B4014610).

ieee



